I found a JENKINS issue dealing with NonCPS
https://issues.jenkins-ci.org/browse/JENKINS-31314

Tried the suggestion in the last comment and only call the NonCPS methods from 
the master node.
Seems I really need to define a heavyweight executor on the master. Reading 
the build cause on a flyweight executor fails or any other heavyweight 
executor than master.

tirsdag 21. juni 2016 08.11.43 UTC+2 skrev Sverre Moe følgende:
>
> I have tried reading the build cause as suggested in this example
>
> https://github.com/jenkinsci/pipeline-examples/tree/master/pipeline-examples/get-build-cause
>
> 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?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/5b3f9231-a257-4160-a6c3-987604e72331%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to