Gitlab webhook does not trigger a build on jenkins

前端 未结 4 1419
野的像风
野的像风 2021-02-07 07:39

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

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

  multib         


        
相关标签:
4条回答
  • 2021-02-07 07:49

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

    We need to specify the name as “origin”, which will be used by the other sections. For the Refspec we need to input: +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*

    And also:

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


    Edit1

    You could try the following for one multibranch pipeline:

    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

    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.

    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
    

    For 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
    

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

    Hope this can help you!

    0 讨论(0)
  • 2021-02-07 08:07

    We were facing similar (not the same) issues with gitlab and Jenkins and the problem was related with the credentials.

    In Jenkins, we created a new global Access token for GitLab (Jenkins Configuration -> Credentials -> System -> New Global access -> Define a gitlab token). That generates a Token that we added it to the Webhook, now the hook being something like:

    http://[Gitlab User]:[token ID]@Jenkins Address
    

    I hope it helps

    0 讨论(0)
  • 2021-02-07 08:10

    I believe you need to use includes() to specify pattern(s) identifying which branches will be included:

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

    You can specify a number of patterns, which can include wildcards. For example:

    includes("master release/* feature/* bugfix/*")
    

    There is also a corresponding excludes() for even finer-grained control.

    0 讨论(0)
  • 2021-02-07 08:10

    Possibly you have configured Basic Branch Build Strategies to only include specific branches e.g. using Exact Name: master which would skip the branch ci from your example.

    Ensure that your Jenkins branch build configuration covers the branches that you are testing for. Also make sure that Suppress automatic SCM triggering option is not set.

    Do note that settings on Organization or Folder level will influence the specific Project and Job settings, unless they are specifically overridden on lower level.

    0 讨论(0)
提交回复
热议问题