plugin development: add global environment settings

51 views
Skip to first unread message

Johann

unread,
Mar 7, 2018, 4:13:24 AM3/7/18
to Jenkins Developers
Hello guys, 

hopefully someone can help me. I am developing a plugin right now, for test purposes and I am wondering how I can make an extra tab for my plugin in Manage Jenkins -> Configure that I am able to make global variables working for every job? 

Daniel Beck

unread,
Mar 7, 2018, 5:43:29 AM3/7/18
to jenkin...@googlegroups.com

> On 7. Mar 2018, at 10:03, Johann <johann....@t-online.de> wrote:
>
> hopefully someone can help me. I am developing a plugin right now, for test purposes and I am wondering how I can make an extra tab for my plugin in Manage Jenkins -> Configure that I am able to make global variables working for every job?

Hi Johann,

Could you clarify what you're asking for? This seems to be two separate questions.

Daniel

Johann

unread,
Mar 7, 2018, 7:05:02 AM3/7/18
to Jenkins Developers
You are right, I am sorry. But I already fixed my problem with the extra tab which I did ask for by creating a global.jelly file. But I have another problem, until now I just had  a config.jelly file which gave me an extra entry in the Build Environment area, and by specify the field="myVar" I was able to parse the value of the textbox and use it in my code. But when I try to get the value of the field entry in my global.jelly, its always null. 

Sry I am new to plugin development and just trying to understand how everything works together

Daniel Beck

unread,
Mar 7, 2018, 7:27:45 AM3/7/18
to jenkin...@googlegroups.com

> On 7. Mar 2018, at 12:49, Johann <johann....@t-online.de> wrote:
>
> by specify the field="myVar" I was able to parse the value of the textbox and use it in my code. But when I try to get the value of the field entry in my global.jelly, its always null.

Make sure you have a public getter for the field.

Johann

unread,
Mar 7, 2018, 8:01:14 AM3/7/18
to Jenkins Developers
My Code:

private String path;

public MyClass(String path) {
    this.path = path;
}

public String getPath() {
    return this.path;
}

and in my global.jelly file:

<f:section title="Section Name">
<f:entry title="Entry Name">
<f:entry title="Path" field="path">
<f:textbox />
</f:entry>
</f:entry>
</f:section>

Not working

Daniel Beck

unread,
Mar 7, 2018, 8:16:07 AM3/7/18
to jenkin...@googlegroups.com

> On 7. Mar 2018, at 14:01, Johann <johann....@t-online.de> wrote:
>
> <f:entry title="Entry Name">
> <f:entry title="Path" field="path">
> <f:textbox />
> </f:entry>
> </f:entry>

Why do you have two nested f:entries? Try with just the inner one.


Johann

unread,
Mar 7, 2018, 8:23:47 AM3/7/18
to Jenkins Developers
I deleted it, but still the path value is null. Also if I go to Manage Jenkins -> Configure and change the value of the textbox and click on Save, its not saving the new value, after refreshing the page the old value is there again.

Johann

unread,
Mar 9, 2018, 3:43:11 AM3/9/18
to Jenkins Developers
guys nobody can help me? Should I show some more of my code?

martinda

unread,
Mar 10, 2018, 8:40:44 AM3/10/18
to Jenkins Developers
Johann,

I cannot help much, but 2 years ago I wrote some code in an attempt to understand how to create global configuration entries. I don't remember much about it.
You can find this code here https://github.com/martinda/jenkins-plugin-globalconfig-demo1

Hope this helps,
Martin

Daniel Beck

unread,
Mar 10, 2018, 10:04:09 AM3/10/18
to jenkin...@googlegroups.com

> On 9. Mar 2018, at 09:43, Johann <johann....@t-online.de> wrote:
>
> guys nobody can help me? Should I show some more of my code?

I think this would be useful.

Stephen Connolly

unread,
Mar 10, 2018, 4:47:50 PM3/10/18
to jenkin...@googlegroups.com
On Sat 10 Mar 2018 at 15:04, Daniel Beck <m...@beckweb.net> wrote:

> On 9. Mar 2018, at 09:43, Johann <johann....@t-online.de> wrote:
>
> guys nobody can help me? Should I show some more of my code

Global.jelly is to configure the descriptor rather than the instance

To use global.jelly you need to expose the getters and setters on your descriptor. Then you need to override the configure method on your descriptor to parse the submitted json (typically you can just say something like req.bind(this,json) if you keep your descriptor “simple” and then call save()... you’ll need to override the descriptor’s constructor to call load() too)

The more modern alternative is to use the GlobalConfiguration stuff... that will have you using a regular config.jelly but iirc you still need some sort of configure(req,json) method to pull the top level in



I think this would be useful.

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/720A9221-83C1-4D26-8481-DD55FBC1A0FA%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone
Reply all
Reply to author
Forward
0 new messages