How do I persist changes to the model made via a Groovy script to disk?

44 views
Skip to first unread message

Christian Goetze

unread,
Mar 16, 2014, 4:07:04 PM3/16/14
to jenkins...@googlegroups.com
I recently learned that I can use the script console to run groovy scripts to modify items in the model.

Specifically, I would like to add, change and remove slave node labels via a script.

I can make a script like this for example:

hudson.model.Hudson.instance.slaves.each { slave -> 
  out.print("Slave  $slave.nodeName : Labels: $slave.labelString")
  slave.setLabelString(slave.labelString + " " + "operational")
  out.println("   --> New labels: $slave.labelString")
}
Now how do I persist this change to disk?

Richard Lavoie

unread,
Mar 16, 2014, 4:37:57 PM3/16/14
to jenkins...@googlegroups.com
Have you tried hudson.model.Hudson.instance.save() ?


--
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.
For more options, visit https://groups.google.com/d/optout.



--
Richard Lavoie
IT consultant / consultant en informatique

Christian Goetze

unread,
Mar 16, 2014, 4:41:50 PM3/16/14
to jenkins...@googlegroups.com
Thank you - that appears to work.


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/epL30VXvXC4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

Christian Goetze

unread,
Mar 16, 2014, 4:42:52 PM3/16/14
to jenkins...@googlegroups.com
What is the best way to discover all these nice things one could do...? Do I really need to fire up an IDE and explore the source?

Richard Lavoie

unread,
Mar 16, 2014, 7:11:54 PM3/16/14
to jenkins...@googlegroups.com
The IDE is the best way because of the inter class easy navigation and the fact that source code is often submitted along with binaries in macen.

You could also just look at the javadocs but I don't think it's published online. It is available through maven though.

Going from the source with IDE is the easiest path.

Richard Lavoie

Richard Bywater

unread,
Mar 16, 2014, 7:22:20 PM3/16/14
to jenkins...@googlegroups.com
Its available online @ http://javadoc.jenkins-ci.org/

Richard.

Richard Lavoie

unread,
Mar 16, 2014, 7:50:08 PM3/16/14
to jenkins...@googlegroups.com
Sweet,

But do we have for LTS or previous versions ?

Richard Lavoie

Daniel Beck

unread,
Mar 17, 2014, 7:31:18 AM3/17/14
to jenkins...@googlegroups.com

Baptiste Mathus

unread,
Mar 19, 2014, 3:15:17 AM3/19/14
to jenkins...@googlegroups.com

+1 having both tried the javadoc and ide path in the past, I recommend by far the ide.
Discovering code and possibilities through javadoc solely proves terribly cumbersome.
Cheers

Reply all
Reply to author
Forward
0 new messages