Jobs have a launchedByUser defined as a property reference.
Common use cases for launchedByUser include:
- User to send a notifier
- In the notifier template
- Resource allocation which is workflow or job sensitiver
- In a runCondition
- In reports
There are considerations when using launchedByUser:
- Only launchedByUser is set - this means the user called runProcedure and passed projectName and procedureName. In this case, the UI shows a link to the user’s details page.
- Only scheduleName is set - this means it was a scheduled job, not launched by a user at all. In this case, the UI shows a link to the schedule’s details page.
- Both launchedByUser and scheduleName are set - this means the user called runProcedure and passed projectName and scheduleName (a manual run of a schedule). In this case, the UI shows a link to the user’s details page.
If you want to, you can figure out whether it’s the first or third case by calling getJobDetails to see if a scheduleName is set, or checking the summary at the top of the job details page to see if a schedule is displayed underneath the project and procedure.
- The object the launchedByUser is referring to is the full User object. To make the user explicit, add the “userName” property.
- Use the launchedByUser to index into the users object to find the login user.
- The job launchedByUser is associated with the job. In workflows and in workflow notifiers the job launchedByUser is not set.
Use the same approach in workflows as in the job. To have the launchedByUser reference work in a workflow or in a job with these following additional considerations:
- If you don’t have a workflow launchedByUser it is because you are on a subworkflow, walk up the workflow to find the parents launchedByUser if it exists
If a schedule runs a job, then the launchedByUser field is blank. CloudBees CD (CloudBees Flow) displays the name of the schedule in the scheduleName property.
The confusion comes from the “launched by” column on the jobs page in the UI, which is either the launchedByUser (if launched by a user) or the scheduleName (if launched by a schedule).
The intrinsic property /myUser is available only when not in a step, i.e. from the ectool commandline after login. See the OLH for more details. launchedByUser is the proper way to reference a user in a workflow or subprocedure or step.