Reputation: 758
I have 2 jobs in Jenkins: Parent and Child (a successful build on Parent triggers a build on Child).
There is a property VALUE in both projects:
What I want is if I build the job Child directly, VALUE=NEXT. But if the job Child is started by the upstream job Parent, the property is overwritten and VALUE=FIRST.
I tried setting a post-build action on Parent to trigger a parameterized build on Child and defined the parameter VALUE=FIRST. However after running Parent and triggering a build on Child, I looked at the console output for Child and VALUE=NEXT: it did not change.
(I tested passing the parameter VALUE to Child if VALUE is undefined in Child and it worked, VALUE equaled FIRST. So Jenkins is able to pass the parameter but it's not able to overwrite the parameter if it's already defined in the downstream job.)
How do I overwrite the property in the downstream job?
Upvotes: 3
Views: 1683
Reputation: 297
This is old post , but I think its worth giving second option to find if current build is caused by upstream project.
`def upstreamProjectCount = 0;
currentBuild.upstreamBuilds?.each { b ->
upstreamProjectCount++
}
if (upstreamProjectCount == 0) {
echo "Not a upstream project"
} else {
echo "upstream project"
}
Upvotes: 2
Reputation: 4678
Please note that this requires some approvals if you run your scripts in sandbox.
isUpstreamTriggered = (currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause) != null)
For more information the example I've based on and the actual Cause class.
Upvotes: 2