You need to do all the work with non-serializable objects inside the
@NonCPS annotated function and return a serializable object.

In your example you are storing the result of `getLastBuildCause` outside
the non-cps function. Try return a `String` there.

On Tue, Jun 21, 2016 at 8:32 AM, Sverre Moe <sverre....@gmail.com> wrote:

> 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 jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/5b3f9231-a257-4160-a6c3-987604e72331%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/5b3f9231-a257-4160-a6c3-987604e72331%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Antonio Muñiz
Software Engineer
CloudBees, Inc.

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAJc7kzSVEFybtn%3DTbo20wbC0nvaKbi%3Dm7MrYkh%3DwfcF7X6ahnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to