Jenkinsfile and different strategies for branches

前端 未结 7 1656
星月不相逢
星月不相逢 2021-01-31 03:23

I\'m trying to use Jenkins file for all our builds in Jenkins, and I have following problem. We basically have 3 kind of builds:

  • pull-request build - it will be me
7条回答
  •  鱼传尺愫
    2021-01-31 03:30

    We followed the model used by fabric8 for builds, tweaking it as we needed, where the Jenkinsfile is used to define the branch and deployment handling logic, and a release.groovy file for build logic.

    Here's what our Jenkinsfile looks like for a pipeline that continuously deploys into DEV from master branch:

    #!groovy
    import com.terradatum.jenkins.workflow.*
    
    node {
    
      wrap([$class: 'TimestamperBuildWrapper']) {
        checkout scm
    
        echo "branch: ${env.BRANCH_NAME}"
        def pipeline = load "${pwd()}/release.groovy"
    
        if (env.DEPLOY_ENV != null) {
          if (env.DEPLOY_ENV.trim() == 'STAGE') {
            setDisplayName(pipeline.staging() as Version)
          } else if (env.DEPLOY_ENV.trim() == 'PROD') {
            setDisplayName(pipeline.production() as Version)
          }
        } else if (env.BRANCH_NAME == 'master') {
          try {
            setDisplayName(pipeline.development() as Version)
          } catch (Exception e) {
            hipchatSend color: 'RED', failOnError: true, message: "

    BUILD FAILED:

    Check console output at ${env.JOB_NAME} [${env.BUILD_NUMBER}]

    ${e.message}

    ", notify: true, room: 'Aergo', v2enabled: false throw e; // rethrow so the build is considered failed } } else { setDisplayName(pipeline.other() as Version) } } } def setDisplayName(Version version) { if (version) { currentBuild.displayName = version.toString() } }

    Note: you can find the code for our global pipeline library here.

提交回复
热议问题