Reputation: 14076
I've a following pipeline where I'm trying to get user who started it -
isStartedByUser = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
pipeline {
agent {
label {
label "<node-name>"
}
}
stages {
stage('Testing') {
steps {
script {
println "Started by " + isStartedByUser
}
}
}
}
}
When run build, it is marked as failed but no error in the console output -
Started by hudson.model.Cause$UserIdCause@f42b6809
[Pipeline] }
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] }
[Pipeline] End of Pipeline
Finished: FAILURE
Please help to understand why it's failing without an issue.
Upvotes: 0
Views: 258
Reputation: 3257
The type of the returned object of currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
is model.hudson.Cause
, which is not serializable.
Reference: https://javadoc.jenkins-ci.org/hudson/model/Cause.html (It does not implement the Serializable
interface)
Depending on your needs you could just add a toString()
to solve your issue or place it into a separat method:
toString():
isStartedByUser = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).toString()
Method:
def getCause() {
return currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause);
}
The original exception has been thrown but swallowed for some reason. You can prove it by adding the environment block to your pipeline. By executing the pipeline you will see the exception now.
environment {
isStartedByUser = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
}
Upvotes: 1