Search code examples
jenkinsjenkins-pluginsjenkins-pipeline

Get github webhook info from pipeline script in Jenkins


Is it possible to get github webhook info from jenkins pipeline script?
For example, i want to know branch name and repo url. And further it will be used in cloning github repository to local machine:

git credentialsId: 'xxx', url: 'xxx', branch: 'xxx'

Solution

  • I solved this problem by printing out the env variables that are available to the job by:

    echo "env:  ${env.getEnvironment()}"
    

    and see what is available.

    I'm using Github and seeing:

    BRANCH, BRANCH_NAME, CHANGE_AUTHOR, CHANGE_AUTHOR_DISPLAY_NAME, CHANGE_BRANCH, CHANGE_ID, CHANGE_TARGET, CHANGE_TITLE, CHANGE_URL...