如果其他条件在Jenkinsfile中不起作用

zvokhttg  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(144)

因此,我尝试在脚本化的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

5ktev3wc

5ktev3wc1#

试试下面的条件。

if(params.ENVIRONMENT.equals("dev") || params.ENVIRONMENT.equals("uat"))

字符串

相关问题