Linking to Downstream Freestyle Job from Workflow Job

46 views
Skip to first unread message

Rick King

unread,
Jun 4, 2015, 3:17:49 PM6/4/15
to jenkins...@googlegroups.com
I'm trying to use a Workflow (ver 1.6) to string together a series of freestyle jobs.

What I believe I'm seeing is that a minimal Job object is returned in the event that the freestyle job completes successfully.  If the downstream freestyle job either fails or is aborted though, I get an exception raised that includes the result as its text... but not much of anything else.

My goal is to provide a linkage within my Workflow job to each of these downstream jobs, but as it stands now I'm only seeing that I can identify it if everything goes just right.

Here's an example snippet of what I'm doing currently:


try {
    def buildStatus = build job: DOWNSTREAM_BUILD 

    def result = buildStatus.getResult()                                           
    def number = buildStatus.getNumber()
                                           
    def url = "http://jenkins.mydomain.com/job/" + DOWNSTREAM_BUILD + "/" + number.toString() + "/"
    echo url

}  catch(e) {                   
    echo e.getMessage()
    error 'DOWNSTREAM_JOB did not start/complete normally'                                        
}

My biggest concern is that I can't figure out to get the corresponding build information in the event of a failure.  Past that, I'd also really like to avoid having to embed the base URL of my server... it seems like I ought to be able to get that from the job I'm running.

Does anyone have ideas on this?  Am I approaching this the wrong way?  Or is this a limitation of the Workflow plugin today?

Rick

Rick King

unread,
Jun 8, 2015, 10:21:15 AM6/8/15
to jenkins...@googlegroups.com
We figured out this morning after looking at the code that returns the status in the plugin a way to get this working:

    https://github.com/jenkinsci/workflow-plugin/blob/1c8d22ab0ee7471d0ceb56b03070579d873bf9b8/support/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerListener.java


If 'Propagate errors' is deselected for this step, it will always return the RunWrapper object on completion rather than only returning it upon success.  


Since we've now disabled the ability for the workflow job to detect that the downstream job failed automatically, we now need to parse the results returned to use to check for how the build turned out.


Hope this helps anyone else who might be having similar troubles.


Rick

Reply all
Reply to author
Forward
0 new messages