2

I would like to know if there is a way to get the username who executed the job and use it in the job which has been executed ?

If my question isn't clear, here is an example :

An user 'bobby' connects to rundeck and execute the job 'lets_go_to_the_moon' In the job 'lets_go_to_the_moon' I want to get 'bobby' in a variable and use it to store this information in a database for example.

Ps : I know that this information can be retrieve in the database dedicated to rundeck, but is there a native variable dedicated to get this kind of information ? And if yes, how ?

Thank you guys, Happy day !

Valentin
  • 25
  • 5

1 Answers1

4

You can use job.username context variable.

Command step format: ${job.username}

Inline-script format: @job.username@

"External" script format: $RD_JOB_USERNAME

If you are dispatching an "external" script to a remote node, take a look at this.

Here you can see all context variables available.

MegaDrive68k
  • 3,768
  • 2
  • 9
  • 51
  • Thanks a lot bro ;) I would loved to upvote your answer but I didn't have enough reputation :( – Valentin Apr 14 '21 at 09:32
  • No worries! Happy to help :-) – MegaDrive68k Apr 14 '21 at 12:59
  • Also, do you know if it's possible to get the logged username and put it in a "remote URL allowed value" option type ? The goal is to send the info to a web service. I've tried to put the 3 variables format you've shared (${job.username} / @job.username@ / $RD_JOB_USERNAME) but none of them returns me the name of the logged user – Valentin Apr 15 '21 at 08:23
  • A good way to send info to a web service is to use the HTTP workflow step plugin: https://github.com/rundeck-plugins/http-step you can use ${job.username} on any plugin parameter. – MegaDrive68k Apr 16 '21 at 13:05
  • Hi MegaDrive68k, thanks for this share, I will surely install it ! But my goal here is to create a dynamic option with information got from a WS and with the rundeck logged user in parameter for the WS. If I pass thought a step, nothing will change in the job options. – Valentin Apr 19 '21 at 08:43
  • Well, I found my answer by myself ^^ If it can help anyone else, you have to use this variable in your job option : ${job.user.name} – Valentin Apr 19 '21 at 08:51
  • Amazing! Good news then :-) – MegaDrive68k Apr 19 '21 at 16:37
  • The last link is dead, but a backup can be found here https://web.archive.org/web/20210728003530/https://docs.rundeck.com/docs/administration/projects/node-execution/ssh.html#passing-environment-variables-through-remote-command – Gourneau Nov 23 '22 at 00:03
  • Link update with the "new" docs entry: https://docs.rundeck.com/docs/manual/projects/node-execution/ssh.html#passing-environment-variables-through-remote-command thanks :) – MegaDrive68k Nov 23 '22 at 11:08