plugin development: add global environment settings

已查看 51 次
跳至第一个未读帖子

Johann

未读,
2018年3月7日 04:13:242018/3/7
收件人 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

未读,
2018年3月7日 05:43:292018/3/7
收件人 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

未读,
2018年3月7日 07:05:022018/3/7
收件人 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

未读,
2018年3月7日 07:27:452018/3/7
收件人 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

未读,
2018年3月7日 08:01:142018/3/7
收件人 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

未读,
2018年3月7日 08:16:072018/3/7
收件人 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

未读,
2018年3月7日 08:23:472018/3/7
收件人 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

未读,
2018年3月9日 03:43:112018/3/9
收件人 Jenkins Developers
guys nobody can help me? Should I show some more of my code?

martinda

未读,
2018年3月10日 08:40:442018/3/10
收件人 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

未读,
2018年3月10日 10:04:092018/3/10
收件人 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

未读,
2018年3月10日 16:47:502018/3/10
收件人 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
回复全部
回复作者
转发
0 个新帖子