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.