I'm trying to add if condition for environment variables in Jenkins Pipeline script
我正在尝试为Jenkins管道脚本中的环境变量添加IF条件
This is the code I wrote
这是我写的代码
environment {
if (BRANCH == 'production' && $REGION == "us-east-1" ) {
CRED = "username"
}
else if (BRANCH == 'production'){
CRED = "Username"
}
else {
CRED = "user"
}
}
steps
{
Credentials([
usernamePassword(credentialsId: env.CRED
}````
I'm getting following error. Not sure what needs to be changed
No variables specified for environment
更多回答
优秀答案推荐
You can't use script in environment
clause, and if
clause is script.
您不能在环境子句中使用脚本,并且IF子句是脚本。
But you can use this:
但你可以使用这个:
environment {
CRED = (BRANCH == 'production') ? (REGION == "us-east-1" ? "Username" : "username") : "User"
}
更多回答
我是一名优秀的程序员,十分优秀!