How to add webhooks in gitlab for multibranch pipeline jenkins

折月煮酒 提交于 2020-01-13 12:13:13

问题


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.


回答1:


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:

  • http://JENKINS_URL/project/PROJECT_NAME
  • http://JENKINS_URL/project/FOLDER/PROJECT_NAME

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.



来源:https://stackoverflow.com/questions/52148634/how-to-add-webhooks-in-gitlab-for-multibranch-pipeline-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!