1

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'
daspilker
  • 8,154
  • 1
  • 35
  • 49
Anatoli
  • 889
  • 2
  • 15
  • 33
  • Can you provide more information on how you configured your Github webhook ? Are you using Github organization plugin, or you only using a pure Github webhook triggering a Jenkins job... ? – Pom12 Sep 13 '16 at 07:58
  • My job is triggered, so I receive payload. I use simple Github webhook. – Anatoli Sep 14 '16 at 19:30

2 Answers2

1

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...
Marko Vranjkovic
  • 6,481
  • 7
  • 49
  • 68
-1

I think the better way to do what you want is to use https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Multibranch+Plugin. By using this plugin and this answer - same question - you can find the branch name.

Community
  • 1
  • 1