Jenkinsfile and different strategies for branches

前端 未结 7 1739
星月不相逢
星月不相逢 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:45

    Don't know if this what you want.. I prefer because it's look more structured.

    Jenkinsfile

    node {
        def rootDir = pwd()
    
        def branchName = ${env.BRANCH_NAME}
    
        // Workaround for pipeline (not multibranches pipeline)
        def branchName = getCurrentBranch()
    
        echo 'BRANCH.. ' + branchName
        load "${rootDir}@script/Jenkinsfile.${branchName}.Groovy"
    }
    
    def getCurrentBranch () {
        return sh (
            script: 'git rev-parse --abbrev-ref HEAD',
            returnStdout: true
        ).trim()
    }
    

    Jenkinsfile.mybranch.Groovy

    echo 'mybranch'
    // Pipeline code here
    

提交回复
热议问题