2

I want to trigger a Jenkins Job if there is code commit made to Gitlab

I am using WebHooks for this: enter image description here

The URL I am trying is

http://10.192.39.32:1024/job/SCMSnaps/buildWithParameters?token=secretkey&SNAP=$GIT_COMMIT

I want SNAP to hold the value of the SHA Number on the Gitlab

can anyone help with the correct way to pass variables in a WebHook URL?

Akki
  • 2,179
  • 8
  • 21
  • 37
  • The commit hash is in the payload GitLab sends. As far as I am aware you can't pass parameters in the URL. Jenkins has a special integration for GitLab so it can read the POST Payload. As for SNAP I don't know. – Fairy Feb 16 '17 at 15:20
  • @Fairy: We can pass parameters in URL. The above URL just does that, I want that parameter to be a variable like $GIT_COMMIT – Akki Feb 16 '17 at 19:24
  • What Fairy is saying is that Gitlab cannot set the parameters in the URL, only in the post payload. The webhook can also be triggered for a comment for example, how would it set this parameter in that case ? You have to interpret the POST payload within jenkins to get the commit hash. – CCH Feb 17 '17 at 09:35

1 Answers1

1

You should install the gitlab hook plugin for jenkins, it will allow you to do just what you want :
https://wiki.jenkins-ci.org/display/JENKINS/Gitlab+Hook+Plugin

CCH
  • 1,516
  • 1
  • 13
  • 24