
例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"
}
}