GitHub webhook can't connect to Jenkins inside VPN? - jenkins

I am setting up continuous integration using Jenkins and GitHub Enterprise.
So far I have been able to easily create Jenkins projects and run jobs regularly.
Jenkins is using SSH public/private keys to authenticate and clone GitHub repos.
Jenkins runs on a Linux server that is inside my company's VPN network.
My next step is to configure Jenkins/GitHub so that each git push to GitHub would trigger a Jenkins build job. I have set up the post-commit webhook on GitHub, and enabled the GitHub hook trigger for GITScm polling checkbox in my Jenkins projects.
However, GitHub fails to connect to Jenkins.
Here is the log:
We couldn’t deliver this payload: failed to connect
{
"zen": "Design for failure.",
"hook_id": 287451636,
"hook": {
"type": "Repository",
"id": 287451636,
"name": "web",
"active": true,
"events": [
"push"
],
"config": {
"content_type": "json",
"insecure_ssl": "0",
"url": "http://1.2.3.4/jenkins/github-webhook/"
},
"updated_at": "2021-03-19T07:45:12Z",
"created_at": "2021-03-19T07:45:12Z",
"url": "https://api.github.com/repos/mycompany/my_repo/hooks/287451636",
"test_url": "https://api.github.com/repos/mycompany/my_repo/hooks/287451636/test",
"ping_url": "https://api.github.com/repos/mycompany/my_repo/hooks/287451636/pings",
"last_response": {
"code": null,
"status": "unused",
"message": null
}
},
"repository": {
"id": 347030450,
"node_id": "MDEwOlJlcG9zaXRvcnkzNDcwMzA0NTA=",
"name": "my_repo",
"full_name": "mycompany/my_repo",
"private": true,
"owner": {
"login": "mycompany",
"id": 11980925,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjExOTgwOTI1",
"avatar_url": "https://avatars.githubusercontent.com/u/11980925?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mycompany",
"html_url": "https://github.com/mycompany",
"followers_url": "https://api.github.com/users/mycompany/followers",
"following_url": "https://api.github.com/users/mycompany/following{/other_user}",
"gists_url": "https://api.github.com/users/mycompany/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mycompany/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mycompany/subscriptions",
"organizations_url": "https://api.github.com/users/mycompany/orgs",
"repos_url": "https://api.github.com/users/mycompany/repos",
"events_url": "https://api.github.com/users/mycompany/events{/privacy}",
"received_events_url": "https://api.github.com/users/mycompany/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/mycompany/my_repo",
"description": "My test repo.",
"fork": false,
"url": "https://api.github.com/repos/mycompany/my_repo",
"forks_url": "https://api.github.com/repos/mycompany/my_repo/forks",
"keys_url": "https://api.github.com/repos/mycompany/my_repo/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/mycompany/my_repo/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/mycompany/my_repo/teams",
"hooks_url": "https://api.github.com/repos/mycompany/my_repo/hooks",
"issue_events_url": "https://api.github.com/repos/mycompany/my_repo/issues/events{/number}",
"events_url": "https://api.github.com/repos/mycompany/my_repo/events",
"assignees_url": "https://api.github.com/repos/mycompany/my_repo/assignees{/user}",
"branches_url": "https://api.github.com/repos/mycompany/my_repo/branches{/branch}",
"tags_url": "https://api.github.com/repos/mycompany/my_repo/tags",
"blobs_url": "https://api.github.com/repos/mycompany/my_repo/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/mycompany/my_repo/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/mycompany/my_repo/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/mycompany/my_repo/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/mycompany/my_repo/statuses/{sha}",
"languages_url": "https://api.github.com/repos/mycompany/my_repo/languages",
"stargazers_url": "https://api.github.com/repos/mycompany/my_repo/stargazers",
"contributors_url": "https://api.github.com/repos/mycompany/my_repo/contributors",
"subscribers_url": "https://api.github.com/repos/mycompany/my_repo/subscribers",
"subscription_url": "https://api.github.com/repos/mycompany/my_repo/subscription",
"commits_url": "https://api.github.com/repos/mycompany/my_repo/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/mycompany/my_repo/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/mycompany/my_repo/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/mycompany/my_repo/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/mycompany/my_repo/contents/{+path}",
"compare_url": "https://api.github.com/repos/mycompany/my_repo/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/mycompany/my_repo/merges",
"archive_url": "https://api.github.com/repos/mycompany/my_repo/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/mycompany/my_repo/downloads",
"issues_url": "https://api.github.com/repos/mycompany/my_repo/issues{/number}",
"pulls_url": "https://api.github.com/repos/mycompany/my_repo/pulls{/number}",
"milestones_url": "https://api.github.com/repos/mycompany/my_repo/milestones{/number}",
"notifications_url": "https://api.github.com/repos/mycompany/my_repo/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/mycompany/my_repo/labels{/name}",
"releases_url": "https://api.github.com/repos/mycompany/my_repo/releases{/id}",
"deployments_url": "https://api.github.com/repos/mycompany/my_repo/deployments",
"created_at": "2021-03-12T10:40:44Z",
"updated_at": "2021-03-18T13:59:52Z",
"pushed_at": "2021-03-18T13:59:49Z",
"git_url": "git://github.com/mycompany/my_repo.git",
"ssh_url": "git#github.com:mycompany/my_repo.git",
"clone_url": "https://github.com/mycompany/my_repo.git",
"svn_url": "https://github.com/mycompany/my_repo",
"homepage": null,
"size": 3,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Makefile",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main"
},
"sender": {
"login": "MyLogin",
"id": 63738097,
"node_id": "MDQ6VXNlcjYzNzM4MDk3",
"avatar_url": "https://avatars.githubusercontent.com/u/13818097?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MyLogin",
"html_url": "https://github.com/MyLogin",
"followers_url": "https://api.github.com/users/MyLogin/followers",
"following_url": "https://api.github.com/users/MyLogin/following{/other_user}",
"gists_url": "https://api.github.com/users/MyLogin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MyLogin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MyLogin/subscriptions",
"organizations_url": "https://api.github.com/users/MyLogin/orgs",
"repos_url": "https://api.github.com/users/MyLogin/repos",
"events_url": "https://api.github.com/users/MyLogin/events{/privacy}",
"received_events_url": "https://api.github.com/users/MyLogin/received_events",
"type": "User",
"site_admin": false
}
}
What could be the problem?

Well the problem is exactly because github cannot access your internal network.
There's an article in Jenkins Community Blog where author suggests using smee (released under ISC License) for webhooks forwarding.

If using smee to deliver webhooks from GitHub to your VPNed Jenkins (you set up Github to send events to smee.io, and than you use the Smee client to retrieve the events and use them internally on Jenknins), here is a quick way to set it up.
Go to Smee.io and get yourself a "channel", write down the URL you get (for example https://smee.io/Wua8D46nBvJ63nPP).
Install Smee on your Jenkins: sudo npm install --global smee-client
Configure the internal forwarding: smee -u https://smee.io/Wua8D46nBvJ63nPP --path /github-webhook/ --port 8080
Go to your GitHub repository: Settings->Webhooks->Add webhook, and paste the URL under "Payload URL", choose Content type "application/json".
Setup your Smee to run as a service on Jenkins, to start at boot time. You will need two files:
Init script /etc/init.d/smee
systemctl service description file /etc/systemd/system/smee.service
/etc/init.d/smee:
#! /bin/sh
### BEGIN INIT INFO
# Provides: smee
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start SMEE daemon at boot time
# Description: Forwards GitHub webhook notifications to Jenkins.
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/bin/smee
PIDFILE=/var/run/smee.pid
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting smee" "smee"
start_daemon -p $PIDFILE $DAEMON
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping smee" "smee"
killproc -p $PIDFILE $DAEMON
log_end_msg $?
;;
force-reload|restart)
$0 stop
$0 start
;;
status)
status_of_proc -p $PIDFILE $DAEMON atd && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/smee {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0
/etc/systemd/system/smee.service:
[Unit]
Description=smee.io webhook delivery from GitHub
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=jenkins
ExecStart=/usr/bin/smee -u https://smee.io/Wua8D46nBvJ63nPP --path /jenkins/github-webhook/ --port 8080
[Install]
WantedBy=multi-user.target
Start the service: sudo /etc/init.d/smee start
Check the status: sudo /etc/init.d/smee status
The notifications from your repository should now be sent to Jenkins and Jenkins should be able to see and handle them. To quickly check if Jenkins handles any Smee comands, open the "Dashboard->System Log" and search for "smee".

Related

How to Publish to a Private GitHub with Electron-builder NSIS and AppImage?

Electron-builder Version: 20.38.5
Target: Windows ia32 and x64
I'm trying to push the project to GitHub releases in a private repository.
The main target is Win ia32 and x64.
I set the token in the console by:
set GH_TOKEN=<blabla>
And at the package.json file:
"publish": {
"provider": "github",
"repo": "electron-todo-tasks",
"owner": "AndreD23",
"host": "github.com",
"protocol": "https",
"releaseType": "draft",
"token": "<blablabla>",
"private": true
}
I'm the only one who will have access to the project, so updating the token in the file apparently not a problem.
But, when I run:
electron-builder --x64 --ia32 --publish always
It shows me the error:
Error: Cannot cleanup:
Error #1 --------------------------------------------------------------------------------
HttpError: 404 Not Found
"method: undefined url: https://github.com/repos/AndreD23/electron-todo-tasks/releases\n\nPlease double check that your authentication token is correct. Due to security reasons actual status maybe not reported, but 404.\n"
I'll attach the whole error.
2019-03-22T13_04_27_992Z-debug.log
electron publish error.txt
I tried to change the option always to onTag or onTagOrDraft and change releaseType to release.
I tried to manually create a draft on GitHub first, doesn't work.
I tried to make the repository public for tests, not working too.
I tried to regenerate the token twice and updated the envs, console and package.json, doesn't work.
Is there any configuration that I've missed? What I have to do for Electron to publish to GitHub?
At the error, it says that cannot find https://github.com/repos/AndreD23/electron-todo-tasks/releases. Opening it on the web browser, it returns 404. I find the link a bit strange because it adds the word repos after github.com, and removing it in the browser it loads fine. This word is setting automatically?
Thanks #edelCustodio
Reference: https://github.com/electron-userland/electron-builder/issues/3776#issuecomment-486888574
This worked for me, on PowerShell type this
[Environment]::SetEnvironmentVariable("GH_TOKEN","my-personal-token","User")
and be sure that you package.json will be like this:
"build": {
"appId": "com.friasoftit.electron-auto-update",
"productName": "Electron Auto Update",
"publish": [
{
"provider": "github",
"owner": "edelCustodio",
"repo": "electron-auto-update"
}
],
"win": {
"publish": [
"github"
],
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
}
]
}
},
And then I run this command yarn run publish and this is how my publish is on my package.json
"publish": "build --win -p always"
Don't forget to close and open a new PowerShell terminal.
Run windows powerShell from Administrator
Execute [Environment]::SetEnvironmentVariable("GH_TOKEN","<git_hub_token>","User")
Launch or full restart your IDE
Run bozon package windows --publish
Config:
{
"name": "",
"version": "",
"description": "",
"author": "",
"repository": "<repo_url>",
"dependencies": {
"cross-fetch": "^3.0.6",
"electron-builder": "^22.10.5",
"file-loader": "^6.2.0",
"luxon": "^1.26.0",
"node-fetch": "^2.6.1"
},
"license": "ISC",
"devDependencies": {
"bozon": "1.1.3",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"jest": "26.6.3",
"spectron": "13.0.0"
},
"build": {
"appId": "",
"publish": [
{
"provider": "github"
}
],
"win": {}
},
"main": ".eslintrc.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}

Default packer builder without using -only option

I have multiple builders section in my packer template, by default this builds both builder on the cloud provider at the same time.
However, if I want to build only the "amazon-ebs" type on the cloud, and use "docker" type locally I can get this with done with packer build -only=rails <path/to/template.yaml>.
Is there a way I can set the default builder to "rails" in the template without using the -only=rails from the packer CLI option.
"builders": [
{
"name": "rails"
"type": "amazon-ebs",
"region": "us-west-2",
"source_ami": "{{user `rails_web_ami`}}",
"instance_type": "m3.medium",
"ami_name": "deploy-rails-web-{{user `sha`}}",
"availability_zone": "us-west-2c",
"ssh_username": "centos",
"ssh_pty" : "true"
},
{
"name": "docker-local",
"type": "docker",
"pull": "true",
"image": "askb/centos7:latest",
"run_command": [ "-d", "-t", "-i", "{{.Image}}", "/bin/bash"],
"changes": [
"WORKDIR /tmp",
"EXPOSE 8080",
"USER jenkins",
"LABEL buildtime {{isotime \"20060102-150405.000\"}}"
],
"commit": true
}
],
"provisioners": ...
No, you have to use -only there is nothing like "default builder".

SCM-manager CLI to set branch write protection

I have downloaded SCM-manager-CLI
I need to set the branch write protection for GIT repository in SCM-manager through CLI
I have set the same through web-app
I need to do that through CLI as a part of Automation
How to do that?
Hi the cli has currently no support for properties, but you can use the rest api to set the properties:
curl -u scmadmin:scmadmin -v http://localhost:8080/scm/api/rest/repositories -XPOST -H 'Content-Type: application/json' -d '{
"name": "newrepository",
"description": "repository with branch protection",
"type": "git",
"properties": [
{ "key": "branchwp.enabled", "value": true },
{ "key": "branchwp.permissions", "value": "master,userone;develop,#devgroup;" }
],
"permissions": [
{ "name": "userone", "type": "WRITE", "groupPermission": false },
{ "name": "devgroup", "type": "WRITE", "groupPermission": true }
]
}'
The example above creates a new repository with enabled branch protection.

Gitlab to Jenkins webhook with parameters

I'm trying to build a job on my jenkins using Gitlab webhook when pushing into a specific branch.
The only issue I have is that the jenkins job is parameterized. The parameter is the branch name.
Is there an option to add the branch name (its a different branch every time) to the webhook so it will be inserted automatically into the parameter in the jenkins job parameter?
Thanks
GitLab invokes the webhook URL with a JSON payload in the request body that carries a lot of information about the GitLab event that led to the webhook invocation. The JSON payload for the GitLab push event does have branch name information in it -- see the "ref" field in the GitLab webhook push event payload:
{
"object_kind": "push",
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
"checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"user_id": 4,
"user_name": "John Smith",
"user_username": "jsmith",
"user_email": "john#example.com",
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
"project_id": 15,
"project":{
"id": 15,
"name":"Diaspora",
"description":"",
"web_url":"http://example.com/mike/diaspora",
"avatar_url":null,
"git_ssh_url":"git#example.com:mike/diaspora.git",
"git_http_url":"http://example.com/mike/diaspora.git",
"namespace":"Mike",
"visibility_level":0,
"path_with_namespace":"mike/diaspora",
"default_branch":"master",
"homepage":"http://example.com/mike/diaspora",
"url":"git#example.com:mike/diaspora.git",
"ssh_url":"git#example.com:mike/diaspora.git",
"http_url":"http://example.com/mike/diaspora.git"
},
"repository":{
"name": "Diaspora",
"url": "git#example.com:mike/diaspora.git",
"description": "",
"homepage": "http://example.com/mike/diaspora",
"git_http_url":"http://example.com/mike/diaspora.git",
"git_ssh_url":"git#example.com:mike/diaspora.git",
"visibility_level":0
},
"commits": [
{
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"message": "Update Catalan translation to e38cb41.",
"timestamp": "2011-12-12T14:27:31+02:00",
"url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"author": {
"name": "Jordi Mallach",
"email": "jordi#softcatala.org"
},
"added": ["CHANGELOG"],
"modified": ["app/controller/application.rb"],
"removed": []
},
{
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev#dv6700.(none)"
},
"added": ["CHANGELOG"],
"modified": ["app/controller/application.rb"],
"removed": []
}
],
"total_commits_count": 4
}
You may not bind any field in the webhook payload to a Jenkins job parameter automatically. However, there is still a way to access webhook payload information in the Jenkins job. The Jenkins GitLab plugin makes this webhook payload information available in the Jenkins Global Variable env. The available env variables are as follows and they do include branch information:
gitlabBranch
gitlabSourceBranch
gitlabActionType
gitlabUserName
gitlabUserEmail
gitlabSourceRepoHomepage
gitlabSourceRepoName
gitlabSourceNamespace
gitlabSourceRepoURL
gitlabSourceRepoSshUrl
gitlabSourceRepoHttpUrl
gitlabMergeRequestTitle
gitlabMergeRequestDescription
gitlabMergeRequestId
gitlabMergeRequestIid
gitlabMergeRequestState
gitlabMergedByUser
gitlabMergeRequestAssignee
gitlabMergeRequestLastCommit
gitlabMergeRequestTargetProjectId
gitlabTargetBranch
gitlabTargetRepoName
gitlabTargetNamespace
gitlabTargetRepoSshUrl
gitlabTargetRepoHttpUrl
gitlabBefore
gitlabAfter
gitlabTriggerPhrase
Just as you would read Jenkins job parameters from Jenkins Global Variable params in your job pipeline script, you could read webhook payload fields from Jenkins Global Variable env:
params.MY_PARAM_NAME
env.gitlabBranch
Hope, the above information helps solve your problem.
You can do that with the Generic Webhook Trigger plugin. There is also an example of using that plugin with GitLab in the Violation Comments to GitLab page.
The source branch is resolved with the following JSONPath:
$.object_attributes.source_branch

Gitlab Webhook and Jenkins: No Data Received

I have been following the below links in order to integrate Gitlab with Jenkins using web hooks. All the below links mention to receive 'JSON' or 'payload' or token over at Jenkins side, but I do not see anything when I try to echo or print these parameters in the Shell script of Jenkins configurations.
In shell script I have this, but I never receive any payloads:
echo "the build worked! The payload is $payload"
I do see some JSON coming through on /var/log/Jenkins/Jenkins.logs, but I want to see the messages coming in inside my 'Console Output', so that I can use the messages coming in from Gitlab to whether trigger a build or not.
Most of these links mention options are not available via Gitlab. One article was mentioning to convert web hook format to application/json, but there are no such options on the Gitlab UI.
How to process a github webhook payload in Jenkins?
http://chloky.com/github-json-payload-in-jenkins/
Jenkins Settings:
Gitlab webhook:
http://xx.xx.xx.xxx:8080/job/Interim_Build/buildWithParameters?token=TOKEN_NAME
Any help would be great. Thanks.
I suggest you to try two solutions (both working for me):
convert json data from Gitlab webhook using this elegant proxy written in Go https://github.com/akira/githookproxy .
It will take the webhook request, and translate it to a request to the target_url in the format of:
payload: JSON body
START: Start commit hash
END: End commit hash
REFNAME: Ref name
emulate jenkins as a Gitlab CI using this Jenkins plugin https://github.com/jenkinsci/gitlab-plugin
For me the best is the first because it is simple and more transparent.
GitLab and GitHub are two separate products. So, the documentation or links for GitHub webhooks that you are referring will not apply to GitLab webhooks.
GitLab invokes the webhook URL with a JSON payload in the request body that carries a lot of information about the GitLab event that led to the webhook invocation. For example, the GitLab webhook push event payload carries the following information in it:
{
"object_kind": "push",
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
"checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"user_id": 4,
"user_name": "John Smith",
"user_username": "jsmith",
"user_email": "john#example.com",
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
"project_id": 15,
"project":{
"id": 15,
"name":"Diaspora",
"description":"",
"web_url":"http://example.com/mike/diaspora",
"avatar_url":null,
"git_ssh_url":"git#example.com:mike/diaspora.git",
"git_http_url":"http://example.com/mike/diaspora.git",
"namespace":"Mike",
"visibility_level":0,
"path_with_namespace":"mike/diaspora",
"default_branch":"master",
"homepage":"http://example.com/mike/diaspora",
"url":"git#example.com:mike/diaspora.git",
"ssh_url":"git#example.com:mike/diaspora.git",
"http_url":"http://example.com/mike/diaspora.git"
},
"repository":{
"name": "Diaspora",
"url": "git#example.com:mike/diaspora.git",
"description": "",
"homepage": "http://example.com/mike/diaspora",
"git_http_url":"http://example.com/mike/diaspora.git",
"git_ssh_url":"git#example.com:mike/diaspora.git",
"visibility_level":0
},
"commits": [
{
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"message": "Update Catalan translation to e38cb41.",
"timestamp": "2011-12-12T14:27:31+02:00",
"url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"author": {
"name": "Jordi Mallach",
"email": "jordi#softcatala.org"
},
"added": ["CHANGELOG"],
"modified": ["app/controller/application.rb"],
"removed": []
},
{
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev#dv6700.(none)"
},
"added": ["CHANGELOG"],
"modified": ["app/controller/application.rb"],
"removed": []
}
],
"total_commits_count": 4
}
The Jenkins GitLab plugin makes this webhook payload information available in the Jenkins Global Variable env. The available env variables are as follows:
gitlabBranch
gitlabSourceBranch
gitlabActionType
gitlabUserName
gitlabUserEmail
gitlabSourceRepoHomepage
gitlabSourceRepoName
gitlabSourceNamespace
gitlabSourceRepoURL
gitlabSourceRepoSshUrl
gitlabSourceRepoHttpUrl
gitlabMergeRequestTitle
gitlabMergeRequestDescription
gitlabMergeRequestId
gitlabMergeRequestIid
gitlabMergeRequestState
gitlabMergedByUser
gitlabMergeRequestAssignee
gitlabMergeRequestLastCommit
gitlabMergeRequestTargetProjectId
gitlabTargetBranch
gitlabTargetRepoName
gitlabTargetNamespace
gitlabTargetRepoSshUrl
gitlabTargetRepoHttpUrl
gitlabBefore
gitlabAfter
gitlabTriggerPhrase
Just as you would read Jenkins job parameters from Jenkins Global Variable params in your job pipeline script, you could read webhook payload fields from Jenkins Global Variable env:
echo "My Jenkins job parameter is ${params.MY_PARAM_NAME}"
echo "One of Jenkins job webhook payload field is ${env.gitlabMergedByUser}"
Hope, the above information helps solve your problem.

Resources