因此,我尝试在脚本化的Jenkinsfile中使用if-else条件来运行构建,这取决于在管道开始时传递的choice参数。在传递pt
作为ENVIRONMENT参数的choice时,它仍然没有执行else块。
stage("Docker Build") {
echo "1. Environment is ${ENVIRONMENT}"
if (env.ENVIRONMENT == 'dev'||'uat') {
echo "2. Environment is ${ENVIRONMENT}"
echo "This is Dev stage"
docker.image("nexus-az.${dockerBuildImageVersion}").inside("-e HOME=${WORKSPACE}") {
sh 'npm run run-envsub -- --env CONTEXTPATH=/app-${ENVIRONMENT}'
sh 'ng build --configuration=${ENVIRONMENT}-oci --base-href /app-${ENVIRONMENT}/'
}
} else {
echo "3. Environment is ${ENVIRONMENT}"
echo "This is PT stage"
docker.image("nexus-az.${dockerBuildImageVersion}").inside("-e HOME=${WORKSPACE}") {
sh 'npm run run-envsub -- --env CONTEXTPATH=/app-${ENVIRONMENT}'
sh 'ng build --configuration=w${ENVIRONMENT}-oci --base-href /app-${ENVIRONMENT}/'
}
}
字符串
并给出以下输出
[Pipeline] { (Docker Build)
[Pipeline] echo
1. Environment is pt
[Pipeline] echo
2. Environment is pt
[Pipeline] echo
This is Dev stage
[Pipeline] isUnix
.
.
.
+ ng build --configuration=pt-oci --base-href /app-oci-pt/
An unhandled exception occurred: Configuration 'pt-oci' is not set in the workspace.
型
1.我尝试使用if(params. environment == 'dev'||”但看到同样的行为。 1.尝试在stage之前声明
ENVIRONMENT = "${params.ENVIRONMENT}"以将其定义为全局变量,然后使用
if (${ENVIRONMENT} == 'dev'||'uat'),但也没有帮助。 1.添加了多个echo语句来查看ENVIRONMENT的值是什么,它解析为
pt`,但仍然不执行else块。
预期行为:它应该进入else块并打印
[Pipeline] echo
1. Environment is pt
[Pipeline] echo
3. Environment is pt
[Pipeline] echo
This is PT stage
型
1条答案
按热度按时间5ktev3wc1#
试试下面的条件。
字符串