Jenkins API with Groovy: setUpstreamProjects

123 views
Skip to first unread message

Sverre Moe

unread,
Feb 20, 2015, 3:21:02 AM2/20/15
to jenkins...@googlegroups.com
I want to dynamically set the downstream projects with a Groovy script. 

I can get the list of downstream projects, but I cannot find a setter. 
hudson.model.Hudson.instance.items.each { project ->
   
if (project.name.equals("myProject")) {
        project
.getUpstreamProjects().each { upstreamProject ->
            println
("Upstream Project: " + upstreamProject.name)
       
}
   
}
}

Is it possible to set this value from a Groovy script?


When I create the Post-build Action "Build other projects" and add projectB for projectA. Then projectB will list projectA as a upstream project (should it not be downstream?). This I find confusing because projectA is a library used by projectB. So actually then projectB is a upstream project of projectA.
projectA should list projectB as upstream project, and projectB should list projectA as downstream project.

Or perhaps I am getting the meaning of downstream/upstream wrong:


The Groovy script building projectA, should it then set downstream or upstream when it wants to build projectB after a successful build?

Baptiste Mathus

unread,
Feb 20, 2015, 4:42:57 AM2/20/15
to jenkins...@googlegroups.com
Upstream means a project is kind of above of some others in the build lifecycle. See it as a waterfall if you like, and water in a waterfall goes down (more rarely up ;-)).
You also must think of the required building order: to build your final artifact(s). In your case, you must indeed have built projectA before projectB since A is a library used by B. So A is indeed upstream in this regard.

So yes, if you say in A configuration that B should be started after it, then B is indeed downstream to A (and A is upstream to B).

About doing that in Groovy, can't have a look just now, but you have a lot of examples here: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console should be a good starting point.

HTH

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2d8fa4bb-4d2f-4434-9940-396d03fe7a1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Sverre Moe

unread,
Mar 9, 2015, 10:26:25 AM3/9/15
to jenkins...@googlegroups.com, bma...@batmat.net
Have not found any code examples of how to set upstream projects. Neither does it seems possible with the Jenkins API.

I tried to add directly in config.xml
<upstreamProject>myLib++</upstreamProject>
<upstreamProject>myLib2++</upstreamProject>
But it didn't take.

According to both JSON and XML schema both downstreamProject and upstreamProject should be possible.
Reply all
Reply to author
Forward
0 new messages