overexchange
overexchange

Reputation: 1

Jenkins scripted pipeline to trigger for every new commit

Below is the groovy syntax, that checkout develop branch on Build now(manual checkout).

node('node_1'){
    stage('dev-staging'){

        sh "cd ${WORKSPACE}"

        dir('xyz') {
            git branch: 'develop', 
                credentialsId: '71111-222-333-444-43333333a40',
                url: 'ssh://git@10.xx.xx.xx:2222/abc_project/xyz.git'
        }
        dir('def') {
            git branch: 'develop', 
                credentialsId: '71111-222-333-444-43333333a40',
                url: 'ssh://git@10.xx.xx.xx:2222/abc_project/def.git'
        }
    }
}

How to trigger checkout from develop branch, on every new commit on develop branch? automatic trigger but not manual trigger...

Upvotes: 0

Views: 2246

Answers (1)

Sers
Sers

Reputation: 12255

You can use Webhook to trigger your job in Jenkins on new commit. Repeat same settings in gitlab for both xyz and def repos.

Jenkins Settings:

  1. Select Build Triggers try webhooks for push events.
  2. Select Build when a change is pushed to GitLab. GitLab webhook URL: http://yourjenkins/project/yourproject, copy job_url.
  3. Select push events.
  4. Click to Advanced button
  5. Find Allowed branches, select Filter branches by name and enter your branch name.
  6. Save

Gitlab settings: - repeat same steps for xyz repo also.

  1. Got to project integration settings: https://10.xx.xx.xx:2222/abc_project/def/settings/integrations.
  2. Enter into URL textbox job_url from Jenkins http://yourjenkins/project/yourproject, select Push events and press Add webhook

Upvotes: 2

Related Questions