I have tried reading the build cause as suggested in this example
Accessing the build cause outside of a node causes the pipeline to fail right after entering the first stage and without an error or exception.
void main(def args) {
def causes = currentBuild.rawBuild.getCauses()
stage 'Checkout'
node {
scm checkout
}
}
Accessing the build cause within a node throws exception java.io.NotSerializableException: hudson.model.Cause$UserIdCause
void main(def args) {
stage 'Checkout'
node {
def causes = currentBuild.rawBuild.getCauses()
scm checkout
}
}
So I put it within a @NonCPS method, but it still fails the same way as before.
void main(def args) {
stage 'Checkout'
node {
def cause = getLastBuildCause()
scm checkout
}
}
@NonCPS
def getLastBuildCause() {
def causes = currentBuild.rawBuild.getCauses()
return causes.last()
}
I need to find out who or what caused the build, to find out if it is an upstream project. Unless there is some other access methods for this?