Something like this maybe?
import hudson.model.Cause
import hudson.model.Result
import hudson.model.Run
import jenkins.model.Jenkins
def upstreamJob = Jenkins.instance.getItem("Upstream")
def job = Jenkins.instance.getItem("Hourly")
job.builds.each { Run build ->
if (build.result == Result.SUCCESS) {
Cause.UpstreamCause cause = build.getCause(Cause.UpstreamCause.class)
if (cause.pointsTo(upstreamJob)) {
println(build.number)
}
}
}
But you should abort the loop as quickly as possible since a long build
history could lead to a lot of loading records from disk.
/B
On Tue, Nov 17, 2015 at 1:39 PM, <[email protected]> wrote:
> I'm trying to write down a script that will get the Build Number of a
> Build that has been triggered by another job. For example: I have a build
> job that calls two other jobs(Call/trigger builds on other project). When
> the main job is finished with success I would like to get the number of the
> first build job that was triggered from within. The script I'm trying to
> run founds the main job, however I can't get in any way the build number of
> the triggered job.
>
> def job = jenkins.model.Jenkins.instance.getItem("Hourly")
> job.builds.each {def build = itif
> (it.getResult().toString().equals("SUCCESS")) {The rest of the code should go
> here!}
>
> I was trying to find it in the Jenkins java-doc API and online, however
> without any luck. Can somebody please help me with that?
>
> P.S. The script runs after the job has finished(triggered when needed
> only).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/daace113-1f22-43e3-ab19-3442b3ac7033%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/daace113-1f22-43e3-ab19-3442b3ac7033%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Robert Sandell
*Software Engineer*
*CloudBees Inc.*
--
You received this message because you are subscribed to the Google Groups
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS2zaGEKXAutEKiZDCqbDgYkmcgo1XZ2MBp7fJc8mkzjtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.