Monday 20 July 2020

Automatically trigger Jenkins Pipeline on Gitlab push



Imagine you have your git repository hosted on Gitlab, and want to automatically trigger a Jenkins pipeline to build your code when you push on a given branch, for example "develop".

Here are the steps to follow.


1) Download Gitlab plugin for Jenkins.



2)Create a new pipeline on Jenkins.

In this example we named the pipeline "my-pipeline"

When configuring the pipeline, set a webhook on Jenkins as shown here:

































3) Set Jenkins Integration in Gitlab.

Go in your project repository, and configure the integration like here:





























As you can see, the Secret token is the same shown on Jenkins Build Trigger.


4) Create a Jenkins user on Gitlab to clone the repository.

Create the user and then add it as a Developer in your project.






5) Create a Credential set for Jenkins user on Jenkins server.

In Jenkins, go to Credentials, and add a new Credential like this:














6) Add a clone step to your pipeline using the credential just created.

stage('Clone sources') {
  steps {
    git credentialsId: 'gitlab-jenkins-user', branch: 'develop', url: 'https://my.gitlab.org/test.git'
  }        
}


4 comments:

  1. I'm cheerful I found this blog! Every now and then, understudies need to psychologically the keys of beneficial artistic articles forming. Your information about this great post can turn into a reason for such individuals.360DigiTMG pmp certification in malaysia

    ReplyDelete
  2. Great post!! It's good to share this kind of articles and I hope you'll share an article about Data Science. By giving an institute like 360DigiTMG.it is one of the best institutes for certified courses.
    data science course in noida

    ReplyDelete
  3. This post is very simple to read and appreciate without leaving any details out. Great work!
    best data science courses in hyderabad

    ReplyDelete
  4. Such a very useful information!Thanks for sharing this useful information with us. Really great effort.
    digital marketing courses aurangabad

    ReplyDelete