I searched a lot online but did not find an answer to this.
We have two projects A and B, which trigger a common project C as it's pipeline step. Now if A has triggered C (common project), and B also triggers C at around the same time, only one build of C is run and the result is consumed by both A and B. The build status in C shows "Started by upstream project A" and "Started by upstream project B" both.
How do I make project C first complete the build triggered by A and then start a new build for the trigger by B?
I solved my issue by using the lockable resource plugin in Jenkins. So my Jenkinsfile for projects A and B look like this
pipeline {
agent { ... }
stages {
stage('Invoke project C') {
steps {
lock('project-c-lock') {
script {
...
...
}
}
}
}
}
Thus this step is executed only once and synchronization takes place. It's important to have the same lock resource name.