JSh*_*use 1 groovy jenkins jenkins-pipeline
我想创建一个输入步骤来提示用户选择 git 标签。为此,我想用 . 返回的值填充下拉框git tag。
这是我当前的管道:
pipeline {
agent any
stages {
stage('My Stage') {
input {
message "Select a git tag"
parameters {
choice(name: "git_tag", choices: TAGS_HERE, description: "Git tag")
}
}
steps {
echo "The selected tag is: ${git_tag}"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望 TAGS_HERE 成为包含命令给出的输出的变量或方法git tags。
到目前为止我已经尝试过:
/我已经广泛搜索了解决方案,但我能找到的所有示例都通过专门使用脚本化管道步骤或使用不依赖于工作区的命令来避免这两个陷阱。
通过改进@hakamairi的答案,你可以这样做:
pipeline {
agent any
stages {
stage('My Stage') {
steps {
script {
def GIT_TAGS = sh (script: 'git tag -l', returnStdout:true).trim()
inputResult = input(
message: "Select a git tag",
parameters: [choice(name: "git_tag", choices: "${GIT_TAGS}", description: "Git tag")]
)
}
}
}
stage('My other Stage'){
steps{
echo "The selected tag is: ${inputResult}"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5618 次 |
| 最近记录: |