I want to trigger multi-branch pipeline for every push, can anyone please let me know can how can we configure web-hooks in gitlab for multi-branch pipeline.
Step 1: Go the the “Settings” of your Jenkins project. Step 2: Go to the “Build Triggers” section. Step 3: Under the “Build when a change is pushed to Gitlab” checkbox, click the “advanced” button. Step 4: Click the “Generate” button under the “Secret Token” field.
Step 1: go to your GitHub repository and click on 'Settings'. Step 2: Click on Webhooks and then click on 'Add webhook'. Step 3: In the 'Payload URL' field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/.
If you were wondering where the trigger setting is in Multibranch pipeline job settings, this will answers it:
Unlike other job types, there is no 'Trigger' setting required for a Multibranch job configuration; just create a webhook in GitLab for push requests which points to the project's webhook URL.
Source: https://github.com/jenkinsci/gitlab-plugin#webhook-url
You can also provide Gitlab triggers within the Jenkinsfile. You can see examples within the link provided above. This is how I got it work:
pipeline {
agent {
node {
...
}
}
options {
gitLabConnection('GitLab')
}
triggers {
gitlab(
triggerOnPush: true,
triggerOnMergeRequest: true,
branchFilterType: 'All',
addVoteOnMergeRequest: true)
}
stages {
...
}
}
Then in your Gitlab Project go to Settings -> Integrations and type in the Jenkins Job project url in 'URL'. URL should take either form:
Notice that the url does not contain "job" within it and instead uses "project".
Make sure under Triggers, you have "Push Events" checked as well if you want the job to trigger whenever someone pushes a commit.
Finally, run a build against your Jenkinsfile first before testing the webhook so Jenkins will pick-up the trigger settings for Gitlab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With