Jenkins pipeline branch name returns null

后端 未结 7 686
滥情空心
滥情空心 2021-01-03 22:25

I\'m trying to get the name of my branch for a jenkins groovy script. I cannot get the current branch name. I try the following:

stage(\'Check out code\')
ch         


        
7条回答
  •  囚心锁ツ
    2021-01-03 22:59

    My workaround, Don't know if work for someone else..

    def branchName = getCurrentBranch()
    echo 'My branch is' + branchName
    
    def getCurrentBranch () {
        return sh (
            script: 'git rev-parse --abbrev-ref HEAD',
            returnStdout: true
        ).trim()
    }
    

提交回复
热议问题