Get logged user BEFORE job execution

81 views
Skip to first unread message

Giorgio T

unread,
Apr 26, 2022, 8:58:51 AM4/26/22
to rundeck-discuss
I'm trying to choose options for a job execution, and these options should defined respect to logged user in rundeck console.

Eg.
I'm "user1" logged in rundeck, and "user1" is not an admin, so "user1" will have just some options.

To retrieve the options I'm using "option value plugin", but on scripting in this plugin there's no variable that contains the "user1" value.

It seems that ${job.user.name} is not defined in plugin environment.

Has someone find a solution to this issue?

Thanks
Giorgio

rac...@rundeck.com

unread,
Apr 27, 2022, 9:13:37 AM4/27/22
to rundeck-discuss
Hi Giorgio,

Probably a good approach is to use the getUserName method on JobPreExecutionEvent interface. This is available on a custom Job Lifecycle plugin.

Take a look at this, this example, and this example.

Regards.

Giorgio T

unread,
Apr 29, 2022, 11:50:26 AM4/29/22
to rundeck-discuss
Thanks a lot for suggestion.

So we compiled the example suggested and it seems working.

Now we have to capture getUserName, so we'll do:

String optVal = event.getUserName()

but now, how we can assign the optVal to a variable that we can share between plugins in the job environment execution?

Thanks in advance.

Regards
Giorgio

rac...@rundeck.com

unread,
Apr 29, 2022, 4:46:46 PM4/29/22
to rundeck-discuss
Hi Giorgio,

Debugging and trying the plugin, I'm seeing that doesn't exist a way to put that value directly in an option (maybe a tricky/dirty way is to put the value in a JSON file for a cascade option).

Anyway, you can open a new request here.

Greetings.

Giorgio T

unread,
May 2, 2022, 12:31:56 PM5/2/22
to rundeck-discuss
Hi Sirs,

we're spending a lot of time in this issue. 
How are we able to debug the plugin?
It seems that this class:


@Override
public JobLifecycleStatus beforeJobExecution(JobPreExecutionEvent event) throws JobLifecyclePluginException {

String optVal = event.getOptionsValues() != null ? event.getOptionsValues().get(optionName) : null;
if (!secretValue.equals(optVal)) {
return JobLifecycleStatusImpl.builder().successful(false).errorMessage(String.format("The option %s value was incorrect!",optionName)).build();
}

return null;
}


is not able to logging something before job execution.

May you kindly suggest us a way to log before job execution? (before clicking on "run job now")

Thanks in advance.

Giorgio

rac...@rundeck.com

unread,
May 3, 2022, 12:07:02 PM5/3/22
to rundeck-discuss
Hi Giorgio,

I checked printing the content using System.out.println to see the string in the console output, but it seems doesn’t exist a way to put that string directly in an option :/

Regards.
Reply all
Reply to author
Forward
0 new messages