I need get the current log in user in Jenkins, I am using a Groovy parameter but I don't know how to get that,
Thanks,
In order to read the console output in Jenkins, All you need to do is copy and paste the code as a stage in your pipeline script. After the build is run, a file named buildConsolelog. txt will be stored in the home directory of your project.
A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to /script/ url or /scriptText/ . Also, Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactively via groovysh .
The option “Use Groovy Sandbox,” shown below, is available in the Pipeline tab, and it allows the scripts to be run by any user without requiring administrator privileges. In this case, the script is run only by using the internal accessible APIs (which allow you to develop your script by using Groovy).
Within a Pipeline Project (read plugin), Jenkins introduces a domain-specific language (DSL) based on 'Groovy', which can be used to define a new pipeline as a script. The flow that would typically require many “standard” Jenkins jobs chained together, can be expressed as a single script.
You should be able to call:
import hudson.model.User
...
User.current()
From a groovy script to get the current user :-)
def user = build.causes[0].userId
import hudson.model.*
def job = Jenkins.getInstance().getItemByFullName(env.JOB_BASE_NAME, Job.class)
def build = job.getBuildByNumber(env.BUILD_ID as int)
def userId = build.getCause(Cause.UserIdCause).getUserId()
def user = User.current()
println(user);
println(userId);
-----
this is the output
[Pipeline] echo (hide)
SYSTEM
[Pipeline] echo
eefrat
[Pipeline] echo
eefrat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With