我想征求意见,但前提是我们在某个分支上。但是,输入将在何时之前运行。这能用声明式语法来完成吗?
例如,即使分支不是主程序,这也会始终提示。
stage('only on master') {
when {
branch 'master'
}
input { ... }
}发布于 2018-04-24 21:03:28
我看到两种方法:
中检查它
CURRENT_BRANCH = '...' // some value or parameter
stage('only on master') {
if (CURRENT_BRANCH == 'master') {
input {
...
}
}
// be sure to check if input was set or define a default value或
上的git
下面的命令检查当前文件夹是否是git存储库,打印"true“(如果没有repo,则返回错误)
git rev-parse --is-inside-work-tree接下来,打印当前的分支名称。
git branch | grep \* | cut -d ' ' -f2使用这两种方法创建一个设置环境变量的脚本。检查管道上的值,以显示输入
stage('only on master') {
// Set true on IS_ON_MASTER if current branch is master,
// otherwise set false
sh ./check-branch-master.sh
if (env.IS_ON_MASTER) {
input {
...
}
}发布于 2021-10-07 11:35:51
或者您可以使用beforeInput标志
stage('Example Deploy') {
when {
beforeInput true
branch 'production'
}
input {
message "Deploy to production?"
id "simple-input"
}
steps {
echo 'Deploying'
}
}https://devops.stackexchange.com/questions/3951
复制相似问题