How to receive local Git branch name with Jenkins Git plugin?

前端 未结 12 770
闹比i
闹比i 2020-12-12 17:52

I am using Branch Specifier option of Jenkins Git plugin (v2.0) to run build on specific branch, e.g. 1.4.

${GIT_BRANCH} in this case conta

12条回答
  •  甜味超标
    2020-12-12 18:43

    In a pipeline you can do it like this :

    // get arround a git scm anoying feature
    stage ('Bootstrap') {
        sh "echo GIT_BRANCH_LOCAL=\\\"$GIT_BRANCH\\\" | sed -e 's|origin/||g' | tee version.properties"
    }
    
    stage('Checkout') {
        load('version.properties')
        checkout([$class: 'GitSCM', branches: [[name: '**']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: "${GIT_BRANCH_LOCAL}"]], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/webofmars/grails-website.git']]])
    }
    

提交回复
热议问题