Hi Dirk,
Looks like you need to use one of the LabelExpression which are the other
subclass of Label,
in your example case the LabelExpression.Or would be needed.
The code would be
job.setAssignedLabel(
new hudson.model.labels.LabelExpression.Or(
new hudson.model.labels.LabelAtom("unit-tests"),
new hudson.model.labels.LabelAtom("master")
)
)
http://javadoc.jenkins-ci.org/hudson/model/labels/LabelExpression.Or.html
http://javadoc.jenkins-ci.org/hudson/model/Label.html
On Wednesday, 6 June 2012 13:19:09 UTC+1, Dirk Kuypers wrote:
>
> Hi Vincent (and others),
>
> it only works for one assignedNode. I can not figure out what to to if
> I want to assign two label expressions as in may case. The job shall
> run on all machines with the label unit-tests and master assigned. If
> I use it as follows:
>
> job.setAssignedLabel(new
> hudson.model.labels.LabelAtom("unit-tests||master"))
>
> I get the following in the resulting XML:
> <assignedNode>"unit-tests||master"</assignedNode>
> <canRoam>false</canRoam>
>
> which is quite different from what I want:
> <assignedNode>unit-tests||master</assignedNode>
> <canRoam>false</canRoam>
>
> Due to the quote Jenkins is now looking for a label with special
> characters ";unit-tests||master" instead of interpreting the || as
> logical or.:-/
>
> Is it possible to do what I want with groovy?
> BR
> Dirk
>
> 2012/6/5 Dirk Kuypers <[email protected]>:
> > Hi Vincent,
> >
> > many thanks! Seems to work!
> >
> > And I think I will try to re-use your trick to retrieve other class
> names.;-)
> >
> > BR
> > Dirk
> >
> > 2012/6/5 HARDION Vincent <[email protected]>:
> >> Hi,
> >>
> >> A quick check on my system gives me : class
> hudson.model.labels.LabelAtom
> >>
> >> With the given Groovy Script :
> >> def jenkins = hudson.model.Hudson.instance
> >> println jenkins.items[0].assignedLabel.class
> >>
> >>
> >> BR,
> >> Vincent
> >>
> >> ________________________________________
> >> From: [email protected] [
> [email protected]] on behalf of Dirk Kuypers [
> [email protected]]
> >> Sent: Tuesday, June 05, 2012 12:48 PM
> >> To: [email protected]
> >> Subject: Setting assignedNode and canRoam of a project programmatically
> >>
> >> Hi,
> >>
> >> I am trying to set up my unit test Jobs via a groovy script and I am
> >> pretty far now. But I have some questions left because I cannot find
> >> the right example online/I am too new to the Jenkins API. And: I am
> >> not sure if this question would be better placed on jenkinssci-dev...
> >>
> >> I want to set assignedNode and the canRoam element in the resulting
> >> config.xml programmatically. At the moment I am stuck.
> >>
> >> <project>
> >> ...
> >> <assignedNode>unit-tests||master</assignedNode>
> >> <canRoam>false</canRoam>
> >> ...
> >> </project>
> >>
> >> I tried
> >>
> >> job.setAssignedLabel(new Label("unit-tests||master"))
> >>
> >> But Label is an abstract class. How could I achieve what I want to do?
> >>
> >> Thanks for help
> >> Dirk
> >> --
> >> Never trust a short-haired guru
> >
> >
> >
> > --
> > Never trust a short-haired guru
>
>
>
> --
> Never trust a short-haired guru
>