gpt4 book ai didi

Jenkins Pipeline script environment if condition(Jenkins管道脚本环境IF条件)

转载 作者:bug小助手 更新时间:2023-10-27 20:10:00 29 4
gpt4 key购买 nike



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

更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com