jenkins pipeline environmentの定義で条件によって値を変更する#
三項演算子、または関数を利用する
引用:Conditional environment variables in Jenkins Declarative Pipeline - Stack Overflow
pipeline {
agent any
environment {
ENV_NAME = "${env.BRANCH_NAME == "develop" ? "staging" : "production"}"
}
}
pipeline {
agent any
environment {
ENV_NAME = getEnvName(env.BRANCH_NAME)
}
}
// ...
def getEnvName(branchName) {
if("int".equals(branchName)) {
return "int";
} else if ("production".equals(branchName)) {
return "prod";
} else {
return "dev";
}
}