[Plugin development]-Programmatically modify 'Execute Shell' content doesn't take effect.

23 views
Skip to first unread message

icetree521

unread,
Jun 13, 2016, 11:46:18 AM6/13/16
to Jenkins Developers
FreeStyleProject p = (FreeStyleProject) build.getProject();
ORIGIN_BUILDER
= (CommandInterpreter) builder;
NEW_BUILDER
= new Shell("echo hello");
p
.getBuildersList().remove(ORIGIN_BUILDER);
p
.getBuildersList().add(NEW_BUILDER);
p
.save();
p
.doReload();


I am developing a new plugin where it need to modify the content of 'Execute Shell'. Above is my code. The above code 'seems' work fine because I see the content of 'Execute Shell' has been changed as expected. But the problem I met is although the content has been updated, jenkins still execute the old content from the temp 'sh' file(see as below). 

[test] $ sh -xe C:\Users\HZCHEN~1\AppData\Local\Temp\hudson1593723515622610306.sh

Does anyone know why Jenkins still execute the old commands from the temp file? How to tell Jenkins to execute my new 'Execute Shell'?

Jesse Glick

unread,
Jun 13, 2016, 12:13:48 PM6/13/16
to Jenkins Dev
On Mon, Jun 13, 2016 at 11:46 AM, icetree521 <icetr...@gmail.com> wrote:
> I am developing a new plugin where it need to modify the content of 'Execute
> Shell'. Above is my code.

Not sure what ultimately you intend to accomplish, but do not do what
you are doing.

icetree521

unread,
Jun 13, 2016, 9:43:54 PM6/13/16
to Jenkins Developers
Hi Glick,
What I am doing is to inject some parameters into the content of 'Execute Shell'  dynamically.  After some google search , I found there is no method for me to update the content of "Execute Shell" but can only remove the old one and add back the new one. 

Jesse Glick

unread,
Jun 15, 2016, 3:59:18 PM6/15/16
to Jenkins Dev
On Mon, Jun 13, 2016 at 9:43 PM, icetree521 <icetr...@gmail.com> wrote:
> What I am doing is to inject some parameters into the content of 'Execute
> Shell' dynamically. After some google search , I found there is no method
> for me to update the content of "Execute Shell" but can only remove the old
> one and add back the new one.

Maybe set a build variable? For example via `RunListener.setUpEnvironment`?
Reply all
Reply to author
Forward
0 new messages