jenkins - 如何在 Jenkinsfile 的 pieline.agent.node 块中使用构建参数?
问题描述
我正在为 PHP 项目开发 Jenkins 管道。由于我想从项目的根目录运行大部分步骤,因此我设置了customWorkspace
:
pipeline {
agent {
node {
label 'devvm-slave-01'
customWorkspace '/path/to/my/project'
}
}
stages {
stage('build') {
steps {
sh 'pwd'
...
}
}
}
}
它工作正常,但我不喜欢路径是硬编码在Jenkinsfile
.
所以我试图通过使用参数来解决这个问题:
问题是:我还没有找到访问 block 中参数的方法pipeline.agent.node
。我可以在pipeline.stages.stage.steps
章节中阅读和处理它们。但不在node
街区内。
是否有可能/如何访问 Jenkinsnode
部分中的项目参数Jenkinsfile
?
解决方案
您可以像这样传递参数而不是硬编码值customWorkspace
:
pipeline {
agent {
node {
label 'devvm-slave-01'
customWorkspace PROJECT_ROOT
}
}
stages {
stage('build') {
steps {
sh 'pwd'
...
}
}
}
}
推荐阅读
- go - 使用接口来使用不同包中的方法
- node.js - Mongoosastic:TypeError:无法读取未定义的属性“toLowerCase”
- python - 如何在等待输入时保持终端更新?
- reactjs - 如何在反应中显示餐厅开放或关闭的状态
- android - 将数据发送到 api 时,Json 数组正在转换为字符串。如何删除它?
- for-loop - 我不让我插入我想要的矩阵
- python - udp 客户端的权限被拒绝
- javascript - HTML/JS - 一个按钮被另一个按钮阻止并被另一个按钮重置
- javascript - 反转数组(不使用反转) - map & unshift - Javascript
- c# - Newtonsoft.Json 如何使用智能引号解析 json 属性