Get git branch name in Jenkins Pipeline/Jenkinsfile

前端 未结 7 1339
借酒劲吻你
借酒劲吻你 2020-12-13 08:06

I\'ve create a jenkins pipeline and it is pulling the pipeline script from scm.
I set the branch specifier to \'all\', so it builds on any change to any bra

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 08:51

    If you have a jenkinsfile for your pipeline, check if you see at execution time your branch name in your environment variables.

    You can print them with:

    pipeline {
        agent any
    
        environment {
            DISABLE_AUTH = 'true'
            DB_ENGINE    = 'sqlite'
        }
    
        stages {
            stage('Build') {
                steps {
                    sh 'printenv'
                }
            }
        }
    }
    

    However, PR 91 shows that the branch name is only set in certain pipeline configurations:

    • Branch Conditional (see this groovy script)
    • parallel branches pipeline (as seen by the OP)

提交回复
热议问题