Declarative pipeline when condition in post

前端 未结 3 808
無奈伤痛
無奈伤痛 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:05

    Using a GitHub Repository and the Pipeline plugin I have something along these lines:

    pipeline {
      agent any
      stages {
        stage('Build') {
          steps {
            sh '''
              make
            '''
          }
        }
      }
      post {
        always {
          sh '''
            make clean
          '''
        }
        success {
          script {
            if (env.BRANCH_NAME == 'master') {
              emailext (
                to: 'engineers@green-planet.com',
                subject: "${env.JOB_NAME} #${env.BUILD_NUMBER} master is fine",
                body: "The master build is happy.\n\nConsole: ${env.BUILD_URL}.\n\n",
                attachLog: true,
              )
            } else if (env.BRANCH_NAME.startsWith('PR')) {
              // also send email to tell people their PR status
            } else {
              // this is some other branch
            } 
          }
        }     
      }
    }
    

    And that way, notifications can be sent based on the type of branch being built. See the pipeline model definition and also the global variable reference available on your server at http://your-jenkins-ip:8080/pipeline-syntax/globals#env for details.

提交回复
热议问题