Declarative pipeline when condition in post

前端 未结 3 836
無奈伤痛
無奈伤痛 2020-12-30 21:35

As far as declarative pipelines go in Jenkins, I\'m having trouble with the when keyword.

I keep getting the error No such DSL method \'when\' found a

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 22:26

    In the documentation of declarative pipelines, It is mentionned that you can't use when in the post block. when is allowed only inside a stage directive. So what you can do is test the conditions using an if in a script:

    post {
    success {
      script {
        if (${env.BRANCH_NAME} == 'master')
            currentBuild.result = 'SUCCESS'
      }
     }
    // failure block
    }
    

提交回复
热议问题