Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-14436

Explain how to set up Jenkins with GitLab

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 8.8
    • Component/s: Web
    • Labels:
    • Edition:
      Community
    • Production Notes:
      None

      Description

      Write a tutorial explaining how to set up Jenkins for analyzing projects hosted on GitLab.

      With branch analysis (DE+)

      Prerequisites

      Create a Multibranch Pipeline Job

      Create a Multibranch Pipeline in order to automatically analyze all your branches and pull requests.

      1. From Jenkins' dashboard, click New Item and create a Multibranch Pipeline Job.
      2. Under Branch Sources, add a GitLab source and enter the following information:
        1. Credentials: select or add your GitLab credentials.
        2. Repository HTTPS URL: The URL to your GitLab repository (no link, we cannot generate it)
        3. Behavior: make sure Only branches that are not also filed as MRs is selected.
      3. Jump to the Build Configuration section and make sure the parameters are set as follows:
        1. Mode: by Jenkinsfile
        2. Script Path: Jenkinsfile
      4. Click Save

      Create a GitLab Webhook

      Create a Webhook in your repository to trigger the Jenkins job on push. Already have a Webhook configured? Skip this step.

      1. Go to the GitLab Webhook creation page for your repository (no link, we cannot generate it) and enter the following information:
        1. URL: Enter your Jenkins instance URL and add the following path: /gitlab-webhook/post
      2. Under Trigger check the following:
        1. Push events
        2. Merge request events
      3. Click Add webhook.

      Create a Jenkinsfile

      Same as Bitbucket and GitHub tutorials.


      Without branch analysis (CE)

      Prerequisites

      • Gitlab plugin for Jenkins, 1.5.13 or later
      • SonarQube Scanner plugin for Jenkins, 2.11 or later

      Create a Pipeline Job

      Create a Pipeline in order to automatically analyze your main branch.

      1. From Jenkins' dashboard, click New Item and create a Pipeline Job.
      2. Under Build Triggers, choose Build when a change is pushed to GitLab. Write down the webhook URL provided. You will need it when configuring the webhook in GitLab.
        1. Under Enabled GitLab triggers, only select Push events.
        2. Click on Advanced...
        3. Find the Secret token text field, and click on Generate. Write down the secret token. You will need it when configuring the webhook in GitLab.
      3. Under Pipeline, make sure the parameters are set as follows:
        1. Definition: Pipeline script from SCM
        2. SCM: Configure access to your GitLab repository. Make sure to only build your main branch.
        3. Script Path: Jenkinsfile
      4. Click Save

      Create a GitLab Webhook

      Create a Webhook in your repository to trigger the Jenkins job on push. Already have a Webhook configured? Skip this step.

      1. Go to the GitLab Webhook creation page for your repository (no link, we cannot generate it) and enter the following information:
        1. URL: Enter the URL provided under Build Triggers in the previous step.
        2. Secret Token: Enter the token generated under Build Triggers in the previous step.
      2. Under Trigger check the following:
        1. Push events
      3. Click Add webhook.

      Create a Jenkinsfile

      Same as Bitbucket and GitHub tutorials.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wouter.admiraal Wouter Admiraal
              Reporter:
              wouter.admiraal Wouter Admiraal
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: