jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.44k stars 620 forks source link

WEBHOOK VARIABLES #725

Closed BOOMChiefRocka closed 6 years ago

BOOMChiefRocka commented 6 years ago

Context

Hello Everyone,

I'm having trouble for weeks now trying to gather variables from the webhook.

I've declared my freestyle project as parametrized and created an empty string variable with the names described on the documentation, e.g. gitlabBranch.

What I was expecting is that, by declaring the git branch as ${gitlabBranch} (I'm using windows btw), I would be able to clone only the branch that the webhook passed.

The output of my Jenkins job is as follows:

=================================================================== Cloning the remote Git repository Cloning repository http://XXX/XXX/XXX.git

git.exe init C:\Jenkins\workspace\Multirepo@2 # timeout=10 Fetching upstream changes from http://XXX/XXX/XXX.git git.exe --version # timeout=10 using GIT_ASKPASS to set credentials XXX git.exe fetch --tags --progress http://XXX/XXX/XXX.git +refs/heads/:refs/remotes/origin/ git.exe config remote.origin.url http://XXX/XXX/XXX.git # timeout=10 git.exe config --add remote.origin.fetch +refs/heads/:refs/remotes/origin/ # timeout=10 git.exe config remote.origin.url http://XXX/XXX/XXX.git # timeout=10 Fetching upstream changes from http://XXX/XXX/XXX.git using GIT_ASKPASS to set credentials XXX git.exe fetch --tags --progress http://XXX/XXX/XXX.git +refs/heads/:refs/remotes/origin/ Seen branch in repository origin/develop Seen branch in repository origin/develop_EF Seen branch in repository origin/master Seen 3 remote branches git.exe show-ref --tags -d # timeout=10 Checking out Revision 9e16b1012512a7ae0178d154b33cf0d5938516dd (origin/develop) git.exe config core.sparsecheckout # timeout=10 git.exe checkout -f 9e16b1012512a7ae0178d154b33cf0d5938516dd Commit message: "Merge branch 'develop_EF' into 'develop'" git.exe rev-list --no-walk 5bc19d31ed4937bfb41f74048f60992df48eb682 # timeout=10 No emails were triggered.

I guess that Jenkins decide to work with "develop" but I don't know why it chooses that branch, even when the parameter "gitlabBranch" appears to be empty.

I've been reading for weeks and I'm not able to understand how to get this to work.

Please help and regards in advance.

omehegan commented 6 years ago

You mention both GitLab Hook Plugin and GitLab plugin. These are two different plugins that provide basically the same functionality. You only need to use one, and I can only help with the GitLab plugin.

To debug this, please attach the config.xml of your job (redact anything sensitive), and also please describe how you have configured the webhook on the GitLab side which is triggering this job. Specifically, I need to know what URL you are using for the webhook.

BOOMChiefRocka commented 6 years ago

Hello Omehegan,

First of all thank you for your time and interest.

I have uninstalled the Gitlab Hook Plugin as you adviced. Find attached the config.xml config.xml (2).txt

The webhook I'm using is:

image

What I expect is to be able to access the value of the field "target_branch" of the json and maybe some more values like the repo URL.

I've been reading all of your documentation and I've tried many different approaches without success.

Regards and thanks in advance.

omehegan commented 6 years ago

@BOOMChiefRocka your webhook URL is incorrect. That is the problem. The documentation was not as clear as it could be (I just updated it a bit), but the correct webhook is displayed in the Jenkins job config when you set up the GitLab trigger. It should be something like http://JENKINS_URL/project/yourbuildname rather than http://JENKINS_URL/job/yourbuildname/build? etc.

BOOMChiefRocka commented 6 years ago

@omehegan

Hello Omehegan,

Thanks for the tip but i'm afraid that this wasn't enough.

Using the following webhook i get a response HTTP 200, that means OK but doesn't trigger the job execution: http://XXX.XXX.XXX.XXX:8080/project/ejemplo_microservicio/build?delay=0sec

Using the following webhook behaves identically: http://XXX.XXX.XXX.XXX:8080/project/ejemplo_microservicio

Regards

omehegan commented 6 years ago

First, do not append this build?delay=0sec or anything to the webhook URL. Please read the docs, the URL is explained pretty clearly now in the README as well as in the config of the plugin. http://XXX.XXX.XXX.XXX:8080/project/ejemplo_microservicio would be correct assuming your job is named ejemplo_microsevicio.

Second, I can see from the config.xml you attached that you have not configured the plugin to trigger your job. That's why nothing is happening. Please read https://github.com/jenkinsci/gitlab-plugin#job-trigger-configuration

BOOMChiefRocka commented 6 years ago

Hello Omehegan,

Thank you very much, you were right, after setting up the trigger everything works.

Cheers mate!!