[Newbie] Jenkins.instance vs Hudson.instance?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Newbie] Jenkins.instance vs Hudson.instance?

Calvin-2
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

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/f6ab5198-ddf5-406b-bb89-4d3e6bc48f62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Newbie] Jenkins.instance vs Hudson.instance?

Oleg Nenashev
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

On Sunday, April 15, 2018 at 10:32:45 PM UTC+2, Calvin wrote:
I recently watched Sam's <a href="https://www.youtube.com/watch?v=T1x2kCGRY1w" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.youtube.com/watch?v\x3dT1x2kCGRY1w&#39;;return true;" onclick="this.href=&#39;https://www.youtube.com/watch?v\x3dT1x2kCGRY1w&#39;;return true;">video guides on how to modify Jenkins settings via Groovy scripts.

I'm trying to modify the default shell programmatically and running into difficulties.
<a href="https://lh3.googleusercontent.com/-gHahg9EX2x4/WtOVApeTG7I/AAAAAAAA2jY/4boTZPBwJ_E83FqdzhYEPo89ZsG0SLfyQCLcBGAs/s1600/Screen%2BShot%2B2018-04-15%2Bat%2B11.07.49%2BAM.png" style="text-align:center;margin-left:1em;margin-right:1em" title="" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-gHahg9EX2x4/WtOVApeTG7I/AAAAAAAA2jY/4boTZPBwJ_E83FqdzhYEPo89ZsG0SLfyQCLcBGAs/s1600/Screen%2BShot%2B2018-04-15%2Bat%2B11.07.49%2BAM.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-gHahg9EX2x4/WtOVApeTG7I/AAAAAAAA2jY/4boTZPBwJ_E83FqdzhYEPo89ZsG0SLfyQCLcBGAs/s1600/Screen%2BShot%2B2018-04-15%2Bat%2B11.07.49%2BAM.png&#39;;return true;">

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) <a href="http://javadoc.jenkins-ci.org/hudson/tasks/Shell.DescriptorImpl.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins-ci.org%2Fhudson%2Ftasks%2FShell.DescriptorImpl.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwduw7ZmJb20m8VWeSiB0W-qntLw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins-ci.org%2Fhudson%2Ftasks%2FShell.DescriptorImpl.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwduw7ZmJb20m8VWeSiB0W-qntLw&#39;;return true;">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

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/3176f78e-0d2b-4539-b9b2-370a962150da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Newbie] Jenkins.instance vs Hudson.instance?

Calvin-2
Thank you Oleg. I'll dig more into Descriptor.java to get a better understanding.



On Monday, April 16, 2018 at 2:11:23 AM UTC-7, Oleg Nenashev wrote:
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: <a href="https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/Jenkins.java" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fmaster%2Fcore%2Fsrc%2Fmain%2Fjava%2Fjenkins%2Fmodel%2FJenkins.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEf0WhO69ZusSs0Ug11My1NXVKvtA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fmaster%2Fcore%2Fsrc%2Fmain%2Fjava%2Fjenkins%2Fmodel%2FJenkins.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEf0WhO69ZusSs0Ug11My1NXVKvtA&#39;;return true;">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

On Sunday, April 15, 2018 at 10:32:45 PM UTC+2, Calvin wrote:
I recently watched Sam's <a href="https://www.youtube.com/watch?v=T1x2kCGRY1w" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.youtube.com/watch?v\x3dT1x2kCGRY1w&#39;;return true;" onclick="this.href=&#39;https://www.youtube.com/watch?v\x3dT1x2kCGRY1w&#39;;return true;">video guides on how to modify Jenkins settings via Groovy scripts.

I'm trying to modify the default shell programmatically and running into difficulties.
<a href="https://lh3.googleusercontent.com/-gHahg9EX2x4/WtOVApeTG7I/AAAAAAAA2jY/4boTZPBwJ_E83FqdzhYEPo89ZsG0SLfyQCLcBGAs/s1600/Screen%2BShot%2B2018-04-15%2Bat%2B11.07.49%2BAM.png" style="text-align:center;margin-left:1em;margin-right:1em" title="" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-gHahg9EX2x4/WtOVApeTG7I/AAAAAAAA2jY/4boTZPBwJ_E83FqdzhYEPo89ZsG0SLfyQCLcBGAs/s1600/Screen%2BShot%2B2018-04-15%2Bat%2B11.07.49%2BAM.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-gHahg9EX2x4/WtOVApeTG7I/AAAAAAAA2jY/4boTZPBwJ_E83FqdzhYEPo89ZsG0SLfyQCLcBGAs/s1600/Screen%2BShot%2B2018-04-15%2Bat%2B11.07.49%2BAM.png&#39;;return true;">

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) <a href="http://javadoc.jenkins-ci.org/hudson/tasks/Shell.DescriptorImpl.html" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins-ci.org%2Fhudson%2Ftasks%2FShell.DescriptorImpl.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwduw7ZmJb20m8VWeSiB0W-qntLw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins-ci.org%2Fhudson%2Ftasks%2FShell.DescriptorImpl.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwduw7ZmJb20m8VWeSiB0W-qntLw&#39;;return true;">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

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/61b81205-cee0-456c-bd9d-7f19e921a6b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.