0
votes

I created separate Jenkins jobs for each of the three github repositories (app1, app2, and app3). Then there's the deployment and test repositories.

app1 repo(with webhook enabled) => app1 JenkinsJob
app2 repo(with webhook enabled) => app2 JenkinsJob
app3 repo(with webhook enabled) => app3 JenkinsJob
deployment repo(webhook NOT enabled)
test repo(webhook NOT enabled)

Below is the jenkinsfile of app1.(Only GIT_REPO_URL1 differs for app2 & app3).

pipeline {
    environment {
        GIT_REPO_URL1 = 'https://github.com/app1.git'
        GIT_REPO_URL2 = 'https://github.com/deployment.git'
        GIT_REPO_URL3 = 'https://github.com/test.git'
        GIT_REPO_AUTH_CRED = 'abcdefg-123123-321123-qwead-asdqwe123'
    }   agent any
    stages {
        stage('GitClone1') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: 'refs/heads/master']], extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: false, reference: '', trackingSubmodules: false]], userRemoteConfigs: [[credentialsId: "${GIT_REPO_AUTH_CRED}", url: "${GIT_REPO_URL1}"]]])
                echo '========++++++++ GitClone Completed ========++++++++'
            }
        }
        stage('GitClone2') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: 'refs/heads/master']], extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: false, reference: '', trackingSubmodules: false]], userRemoteConfigs: [[credentialsId: "${GIT_REPO_AUTH_CRED}", url: "${GIT_REPO_URL2}"]]])
                echo '========++++++++ GitClone Completed ========++++++++'
            }
        }
        stage('GitClone3') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: 'refs/heads/master']], extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: false, reference: '', trackingSubmodules: false]], userRemoteConfigs: [[credentialsId: "${GIT_REPO_AUTH_CRED}", url: "${GIT_REPO_URL3}"]]])
                echo '========++++++++ GitClone Completed ========++++++++'
            }
        }
    } }

Code delivery on app1/app2/app3 is triggering app1/app2/app3 jenkins jobs respectively.

Now issue is, when i push a code change to https://github.com/deployment.git or https://github.com/test.git repositories, Jenkins pipelines for app1, app2, and app3 are automatically triggered.

Expected Fix: The app jenkins job should be triggered by only code delivery to the app repos.

1
Please add more info on your current triggering mechanism. - Noam Helmer
@NoamHelmer In terms of triggering mechanism, 1. Github side, Added Hook url jenkins-endpoint.com/github-webhook, 2. Jenkins Side, Checked "GitHub hook trigger for GITScm polling" option - Prakash26790

1 Answers

0
votes

The GitSCM class in the checkout step has a dedicated additional behavior for disabling triggers for the configured repository:

Don't trigger a build on commit notifications

If checked, this repository will be ignored when the notifyCommit-URL is accessed regardless of if the repository matches or not.

This attribute can be configured in pipeline by using extension with class IgnoreNotifyCommit.
So to achieve what you want just add this configuration to the checkout options of each repository that should not trigger the job.
For example:

 checkout([$class: 'GitSCM', branches: [[...]], extensions: [[$class: 'IgnoreNotifyCommit'],[$class: 'SubmoduleOption',...]], userRemoteConfigs: [[...]]])