[Newbie] Jenkins.instance vs Hudson.instance?

25 views
Skip to first unread message

Calvin

unread,
Apr 15, 2018, 4:32:45 PM4/15/18
to Jenkins Developers
I recently watched Sam's video guides on how to modify Jenkins settings via Groovy scripts.

I'm trying to modify the default shell programmatically and running into difficulties.

On a different Jenkins instance, I see that hudson.tasks.Shell.xml contains this config

<hudson.tasks.Shell_-DescriptorImpl>

  <shell>bash</shell>

</hudson.tasks.Shell_-DescriptorImpl>


How do I access that field using Groovy?

I found hudson.tasks.Shell.DescriptorImpl.setShell(String shell) doc.
When I tried to access hudson.tasks via Hudson.instance.tasks.dump() I got this error
groovy.lang.MissingPropertyException: No such property: tasks for class: hudson.model.Hudson
Possible solutions: class

1. Jenkins.instance vs Hudson.instance? Which contains what and why?
2. How do I access the setShell() method?

Thanks for your help in advance

Oleg Nenashev

unread,
Apr 16, 2018, 5:11:23 AM4/16/18
to Jenkins Developers
Hi Calvin,


Jenkins.instance vs Hudson.instance? Which contains what and why?
  • There is no real difference. "Hudson.getInstance()" xists for compatibility reasons but returns the same object
Hudson.instance.tasks.dump()

As designed, there is no "tasks" in the Jenkins object: https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/Jenkins.java . Likely you got confused by package names.


How do I access the setShell() method?

It should be something like that (untested):
Jenkins.instance.getDescriptor(hudson.tasks.Shell.class).setShell()
 
Hopefully it helps,
Oleg

Calvin

unread,
Apr 16, 2018, 4:29:10 PM4/16/18
to Jenkins Developers
Thank you Oleg. I'll dig more into Descriptor.java to get a better understanding.
Reply all
Reply to author
Forward
0 new messages