How to access git branch name from pipeline job?

后端 未结 3 1561
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-20 18:32

I have a Jenkins Pipeline job which is configured to checkout a git repo and a specific local branch.

How can i get the name of the local branch in my Jenkinsfile?<

3条回答
  •  失恋的感觉
    2021-02-20 19:01

    I'm now using the sh call to get the branch name. This requires at least version 2.4 of the Pipeline Nodes and Processes Plugin.

    def branchName = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
    echo branchName
    

提交回复
热议问题