1

I have spent days now trying different approaches to get Jenkins trigger when we accept a Merge Request. Unfortunately, I can't get anything to work on our system. I have tried different plugins from Jenkins side of things to trigger GitLab, but they seem not to work either. Adding parameterized strings and adding token to end of URL's, I have tried them all - maybe not in correct order, I'm not sure.

I would like a nice configuration to tell me exactly what settings I have to setup and which plugins to use. I have uploaded most plugins for webhooks and merge request plugins, but none of them really work.

Then, next question is how do I debug what is coming from GitLab over to Jenkins? Do you look at system logs? There seem to be a lot of stuff there, and the same with /var/log/Jenkins/jenkins.log file.

Any help/suggestions is very much appreciated.

GitLab version: 7.12.2 Jenkins version: 1.620

CSchulz
  • 10,882
  • 11
  • 60
  • 114
DevGirl
  • 153
  • 1
  • 8
  • Are you using GitLab Community Edition or Enterprise Edition? If you're using Enterprise Edition, you can follow this documentation: http://docs.gitlab.com/ee/integration/jenkins.html It has instructions on configuring the Jenkins CI service. Unfortunately Community Edition doesn't have this service. – Jamie P Jun 20 '16 at 02:25

1 Answers1

0

I know this is an old question, but here's my setup for doing this on GitLab CE 8.13.12 and Jenkins 2.46.2 using declarative pipelines, and the Gitlab plugin 1.4.5 and Gitlab Hook plugin 1.4.2. These steps will likely work with the latest version as well.

  • Two separate Pipeline jobs
    • The first job is specifically for the MR build
    • The second is for the master branch/repo where the MR gets merged into
  • Both jobs have the Build Trigger "Build when a change is pushed to GitLab" enabled
    • The MR job has the following events enabled
      • Merge Request Events (and rebuild on push to source and target)
      • Comments (and some comment)
    • The master job only has the Push Events trigger enabled, but also has the Advanced Option to filter branches (I only use master as a name)

Then, the pipeline scripts look like this MR

checkout ([
        $class: 'GitSCM',
       branches: [[name: "${env.gitlabSourceNamespace}/${env.gitlabSourceBranch}"]],
       extensions: [
         [$class: 'PruneStaleBranch'],
         [$class: 'CleanCheckout'],
         [
           $class: 'PreBuildMerge',
          options: [
         fastForwardMode: 'NO_FF',
            mergeRemote: env.gitlabTargetNamespace,
            mergeTarget: env.gitlabTargetBranch
          ]
         ]
       ],
       userRemoteConfigs: [
         [
           name: env.gitlabTargetNamespace,
          url: env.gitlabTargetRepoSshURL
         ],
         [
           name: env.gitlabSourceNamespace,
          url: env.gitlabSourceRepoSshURL
         ]
       ]
      ])

master

checkout([
        $class: 'GitSCM', 
        branches: [[name: '*/master']],
        extensions: [
         [$class: 'PruneStaleBranch'],
         [$class: 'CleanCheckout']],
        userRemoteConfigs: [[url: '<my-git-url>']]])

This gives me two jobs. The MR job depends on the GitLab plugin to define what source and target repos and branches to checkout, merge, and build. The master job will only build the master repo.

The last step is to configure the webhooks in GitLab for the repo. When you make a webhook in GitLab, it asks for the following info:

  • Endpoint URL (this is found in the Jenkins job under the Build Triggers section)
  • Events (match the events from the Jenkins job to here)
  • SSL Verification (up to you and your network configuration)

And you should be done!