Git Variables in Jenkins Workflow plugin

前端 未结 7 1517
故里飘歌
故里飘歌 2020-12-08 04:17

I\'d like to access git variables such as GIT_COMMIT and GIT_BRANCH when I have checked out a repository from git further down in the build stream.

7条回答
  •  伪装坚强ぢ
    2020-12-08 04:53

    Depending on the information you need, there is a very straightforward solution: get the "checkout scm" operation return: it provides GIT_BRANCH, GIT_COMMIT, GIT_PREVIOUS_COMMIT, GIT_PREVIOUS_SUCCESSFUL_COMMIT and GIT_URL.

    node { 
        stage ("Checkout") {
    
            scmInfo = checkout scm
    
            /*...*/
            echo "scm : ${scmInfo}"
            echo "${scmInfo.GIT_COMMIT}"
    
    
        }
    }
    

    This will output:

    ...
    [Pipeline] echo
        scm : [GIT_BRANCH:my-branch, GIT_COMMIT:0123456789abcdefabcdef0123456789abcdef01, GIT_PREVIOUS_COMMIT:aaaabbbcccffffdeeeefffe0123456789012345678, GIT_PREVIOUS_SUCCESSFUL_COMMIT:aaaabbbcccffffdeeeefffe0123456789012345678, GIT_URL:http://my.si.te/my-repository.git]
    [Pipeline] echo
        0123456789abcdefabcdef0123456789abcdef01
    ...
    

    More details here Jenkins Pipeline SCM Steps

提交回复
热议问题