如何在gitlab中为多分支管道詹金斯添加Webhooks [英] How to add webhooks in gitlab for multibranch pipeline jenkins

查看:430
本文介绍了如何在gitlab中为多分支管道詹金斯添加Webhooks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为每次推送触发多分支管道,任何人都可以让我知道如何在gitlab中为多分支管道配置Web钩子.

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.

推荐答案

如果您想知道触发器设置在Multibranch流水线作业设置中的什么位置,它将回答以下问题:

If you were wondering where the trigger setting is in Multibranch pipeline job settings, this will answers it:

与其他作业类型不同,多分支作业配置不需要触发器"设置;只需在GitLab中为推送请求创建一个Webhook,即可指向项目的Webhook URL.

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.

来源: https://github.com/jenkinsci/gitlab-plugin#webhook -url

您还可以在Jenkinsfile中提供Gitlab触发器.您可以在上面提供的链接中查看示例.这就是我的工作方式:

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 {
            ...
        }
    }

然后在您的Gitlab项目中转到设置"->集成",然后在"URL"中键入Jenkins Job项目的URL.网址应采用以下任一格式:

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

请注意,该网址中不包含"job",而是使用"project".

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.

最后,在测试Webhook之前,首先对您的Jenkinsfile运行构建,以便Jenkins为Gitlab设置触发设置.

Finally, run a build against your Jenkinsfile first before testing the webhook so Jenkins will pick-up the trigger settings for Gitlab.

这篇关于如何在gitlab中为多分支管道詹金斯添加Webhooks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆