Get git branch name in Jenkins Pipeline/Jenkinsfile

The Solution to Get git branch name in Jenkins Pipeline/Jenkinsfile is


Use multibranch pipeline job type, not the plain pipeline job type. The multibranch pipeline jobs do posess the environment variable env.BRANCH_NAME which describes the branch.

In my script..

stage('Build') {
    node {
        echo 'Pulling...' + env.BRANCH_NAME
        checkout scm
        
    }
}

Yields...

Pulling...master

~ Answered on 2017-05-14 10:47:54


Most Viewed Questions: