jenkins - jenkinsfile 在主代理上执行
问题描述
我开始使用 jenkinsfiles。
jenkins 文件包含一条回显消息(即 Hello world)
这是我的情况:我在带有 so windows(主代理)的 PC 上安装了 jenkins(版本 2.190.1)。我的奴隶代理是一台带有so linux的电脑。我把我的詹金斯文件放在我的 scm 中。我已成功配置管道以运行 jenkinsfile。这是成功完成的。
Jenkins 在 *master agent* 而不是 *slave agent*(我想要的)上进行存储库签出,并且 *option "Lightweight checkout"* 被选中。
我想要这种行为,因为我的管道必须在从代理上工作。而且我不希望我的存储库在主代理上。我在网上搜索了可能的解决方案,但没有结果。
你能给我一个关于如何直接在从代理上签出我的存储库的建议吗?
解决方案
可以这样做。从下面的示例中,只需替换agentLabelName
为您的代理名称。
脚本流水线
node('agentLabelName') {
stage('stageName') {
echo "${env.WORKSPACE}"
//checkout scm // If Jenkinsfile availabe with your SCM
git url: 'https://github.com/samitkumarpatel/test0.git', branch: 'main'
}
}
声明式管道
pipeline {
agent {
label 'agentLabelName'
}
stages {
stage('stageName') {
steps {
echo "Hello World"
echo "${env.WORKSPACE}"
//checkout scm // If Jenkinsfile availabe with your SCM
git url: 'https://github.com/samitkumarpatel/test0.git', branch: 'main'
}
}
}
}
推荐阅读
- github-actions - 如何将 Windows 路径转换为 UNIX 路径
- python - 在 python 3 中为大型数据集查找阈值内的点的最有效方法是什么?
- python - 最后一个字符缺少python
- laravel - Laravel Spatie 权限不会将未经授权的用户重定向到登录页面
- java - 我在 curl 请求中从 spring 过滤器中得到 null
- asp.net - ASP.NET 单元测试:存在同名数据库,或无法打开指定文件
- java - 解析未知xml的Java代码,修改某些节点的内容并将其复制到输出xml
- google-apps-script - 减少 Googlesheets 和 GoogleApps 脚本的导入功能的运行时/执行
- django-rest-framework - 有效负载大小超过 10KB(大约)时出现 CORS 错误
- python - MDLabel 不滚动