How to access git branch name from pipeline job?

后端 未结 3 1553
佛祖请我去吃肉
佛祖请我去吃肉 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:07

    You can use scm attributes to get the list of branches configured for your scm :

    // List of all configured branches
    def allBranches = scm.branches
    
    // Only the first configured branch name
    def gitBranch = scm.branches[0].name
    

提交回复
热议问题