Gitlab Webhook不会触发jenkins的构建 [英] Gitlab webhook does not trigger a build on jenkins

查看:1072
本文介绍了Gitlab Webhook不会触发jenkins的构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组使用以下groovy脚本生成的多分支管道作业:

I've a group of multibranch pipeline jobs generated with the following piece groovy script:

[
      'repo1',
      'repo2',
].each { service ->

  multibranchPipelineJob(service) {

    displayName(service)

    branchSources {
      git {
        remote("git@gitlab.com:whatever/${service}.git")
        credentialsId('gitlab-ssh-key')
      }
    }

    orphanedItemStrategy {
      discardOldItems {
        daysToKeep(0)
        numToKeep(30)
      }
    }

    triggers {
      periodic(5)
    }

  }
}

,在每个存储库中,一个Jenkinsfile如下所示:

and in each repo a Jenkinsfile that looks as follows:

#!/usr/bin/env groovy

properties([
      gitLabConnection('ci@gitlab.com'),
      pipelineTriggers([
            [
                  $class               : 'GitLabPushTrigger',
                  triggerOnPush        : true,
                  triggerOnMergeRequest: true,
            ]
      ]),
      disableConcurrentBuilds(),
      overrideIndexTriggers(false)
])

node {

  def sbtHome = tool name: 'sbt-0.13.15', type: 'org.jvnet.hudson.plugins.SbtPluginBuilder\$SbtInstallation'

  stage('Checkout') {
    checkout scm
  }

  stage('Build') {
    sh "'${sbtHome}/bin/sbt' clean compile"
  }

  stage('Test') {
    sh "'${sbtHome}/bin/sbt' test"
  }

  if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master') {
    stage('Publish') {
      sh "'${sbtHome}/bin/sbt' publish"
    }
  }
}

一切正常. seeder 项目从第一个脚本生成所有文件夹,并且正确构建了给定回购的所有分支.

It all works correctly. The seeder project generates all the folders from the first script and all the branches for given repo are built correctly.

不幸的是,在对gitlab进行提交+推送之后,我无法触发任何分支的构建.

Unfortunately I've problems with triggering a build for any branch after commit + push has been made to gitlab.

我已经正确配置了jenkins-我的意思是gitlab插件,存在连接,并且一切正常.

I've jenkins configured correctly - I mean the gitlab plugin, there is a connection and it all works well.

我还在gitlab端添加了一个webhook,它也可以正常运行.发送测试推送后,我从jenkins收到200 OK,并且在日志中确实看到扫描分支已开始并正确检测到更改.不幸的是,更改后的分支的构建无法启动.这是分支扫描日志的摘录:

I've also added a webhook on the gitlab side and it also runs correctly. After a test push is sent I receive 200 OK from jenkins and I do see in logs that scanning the branches has started and detected the changes correctly. Unfortunately the build for the changed branch does not start. Here's an extract from branch scan log:

  Checking branch ci
      ‘Jenkinsfile’ found
    Met criteria
Changes detected: ci (a7b9ae2f930b0b10d52bb42f1ecf96a68bba4a30 → 39a4c1a65051d5e90079feec14ad22455a77c58e)
Did not schedule build for branch: ci

我100%确信这不是我的jenkins实例与gitlab帐户之间的通信问题.我看到推送到gitlab后触发了Webhook,看到请求正在发送并且分支扫描正在运行.还可以检测到更改,但是为什么地球上的工作还没有开始??我还阅读了

I'm 100% sure that this not a problem with communication between my jenkins instance and gitlab account. I see the webhook being triggered after push to gitlab, I see the request being send and branch scan being run. Changes are also detected but why on earth the job isn't started? I've also read the docs thoroughly and have it all configured correctly.

Jenkins version: 2.150.3
Gitlab version: 11.8.1-ee

编辑

在将詹金斯升级到v.2.164.1之后,一切似乎都可以正常工作了.

It seems that after upgrading jenkins to v.2.164.1 it all started working correctly.

推荐答案

我发现这非常有用持续集成Jenkins和GitLab ).尤其是源代码管理部分:

I found this very useful Setup Example (Continuous Integration with Jenkins and GitLab) . Especially the part Source Code management:

我们需要将名称指定为"origin",其他部分将使用该名称.对于Refspec,我们需要输入:+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*

还有:

分支说明符,我们需要origin/${gitlabSourceBranch},它将根据接下来要设置的网络挂钩进行填充.

Branch Specifier we need origin/${gitlabSourceBranch} which will be filled in based on the web hook we’ll be setting up next.


编辑1

您可以对一个多分支管道尝试以下操作:

You could try the following for one multibranch pipeline:

  1. 选择一个分支,例如ci
  2. 选择查看配置"
  3. 在构建触发器"下,选中将更改推送到GitLab时构建"复选框.
  4. 对代码进行一些更改,然后推送到ci
  1. Select a branch, for example ci
  2. Select "View Configuration"
  3. Under "Build Triggers" select the checkbox "Build when a change is pushed to GitLab"
  4. Make some changes to the code and push to ci


Edit2

我找不到合适的git项目来运行并尝试重现此行为.因此,如果有人知道类似项目并可以分享,请发表评论,我可以进行更多测试.

I could not find a suitable git-project to run and try to reproduce this behaviour. So if someone know a similar project and could share, please comment and I could do some more testing.

对于 Gitlab (要求提供试用版密钥,否则它将是GitLab社区版):

For Gitlab (requested a trial key, otherwise it will be a GitLab Community Edition):

sudo docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ee:11.8.1-ee.0

对于 Jenkins :

sudo docker run  -u root  --rm  -d  -p 8080:8080  -p 50000:50000  -v jenkins-data:/var/jenkins_home  -v /var/run/docker.sock:/var/run/docker.sock  jenkins/jenkins:2.150.3

然后在Gitlab中使用"集成" —>" Jenkins CI ",如下图所示:

Then "Integration" —> "Jenkins CI" in Gitlab as in this image:

希望这可以为您提供帮助!

Hope this can help you!

这篇关于Gitlab Webhook不会触发jenkins的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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