
例1
stage('Master Branch Tasks') {
when {
branch "master"
}
steps {
sh '''#!/bin/bash -l
Do some stuff here
'''
}
}
例2 (not)
stage('Example (Not master nor staging)') {
when {
not {
anyOf {
branch 'master';
branch 'staging'
}
}
}
steps {
sh 'do-non-master-nor-staging.sh'
}
}
使用脚本方式也可以
stage('Example') {
steps {
script {
if (env.BRANCH_NAME != 'master' && env.BRANCH_NAME != 'staging') {
echo 'This is not master or staging'
} else {
echo 'things and stuff'
}
}
}
}
判断自定义参数的值
stage('Example') {
when {
expression { env.ENVIRONMENT == "PROD" }
}
steps {
echo "deplpoyment prod"
}
}
最后
以上就是动人寒风最近收集整理的关于Jenkinsfile中 when语句的内置条件以及使用脚本方式判断的全部内容,更多相关Jenkinsfile中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复