I dont want to used from CurrentBuild or CurrentUser because this return the user information that who build the job , but i wnat to get the user information that login to jenkins. for example the job X run by timer and the one user will aborted this , i want to found that which user aborted this job .
you can use the below code. pay attention when you want to execute this code you have to permit to run these methods by go to " manage Jenkins/in process script Approval" and approve them to be executable. by using this code you can get whom aborted Jenkins pipeline not only in manually running job also in running by timer.
pipeline {
agent any
triggers{cron("*/1 * * * *")}
stages {
stage('Hello') {
steps {
sleep(20000)
echo 'Hello World'
}
}
}
post{
aborted{
script{
def causee = ''
def actions = currentBuild.getRawBuild().getActions(jenkins.model.InterruptedBuildAction)
for (action in actions) {
def causes = action.getCauses()
// on cancellation, report who cancelled the build
for (cause in causes) {
causee = cause.getUser().getDisplayName()
cause = null
}
causes = null
action = null
}
actions = null
echo causee
}
}
}
}