Try nesting that in a script block

pipeline {
    agent any
    stages {
        stage('example') {
            steps {
*              script {*
                def causes = currentBuild.getBuildCauses()
                echo "Causes are ${causes}"
*              }*
            }
        }
    }
}

On Wed, Jul 29, 2020 at 10:04 PM Tom Brownridge <[email protected]>
wrote:

> Hello,
>
> I am new and am fundamentally misunderstanding pipeline syntax and cannot
> relate the examples in the documentation. What am I missing?
>
> Looking at the example here:
> https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/get-build-cause/getBuildCause.groovy,
> I see a code snippet like this:
>
> def causes = currentBuild.getBuildCauses()
>
> But when I try to write a pipeline script to use it:
>
> pipeline {
>     agent any
>     stages {
>         stage('example') {
>             steps {
>                 def causes = currentBuild.getBuildCauses()
>                 echo "Causes are ${causes}"
>             }
>         }
>     }
> }
>
> I get the following error:
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> WorkflowScript: 6: Expected a step @ line 6, column 17.
>                    def causes = currentBuild.getBuildCauses()
>                    ^
>
> 1 error
>
>       at 
> org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
>       at 
> org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
>       at 
> org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
>       at 
> org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
>       at 
> org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
>       at 
> groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
>       at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
>       at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
>       at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
>       at 
> org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
>       at 
> org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
>       at 
> org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
>       at 
> org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
>       at 
> org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
>       at hudson.model.ResourceController.execute(ResourceController.java:97)
>       at hudson.model.Executor.run(Executor.java:428)
> Finished: FAILURE
>
> Thanks in advance.
>
> Sincerely,
> Tom
>
>
>
>
>
>
> --
> 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/da7f2288-490d-40f5-ad6f-693ea3869bdbo%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/da7f2288-490d-40f5-ad6f-693ea3869bdbo%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
[image: Backbase] <https://backbase.com/>*Gavin Davies*
Senior System Engineer · R&D BA Cardiff Tribe · Cardiff
*O* +31 (0) 20 465 8888
LinkedIn <https://www.linkedin.com/company/backbase> · Twitter
<https://www.twitter.com/backbase> · Careers <https://workatbackbase.com/>

-- 
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/CAONG3Zw4GDUUAzV2JL7GSk%2BWNYwuPXc%2B3eAHMg3D23K23YvhpA%40mail.gmail.com.

Reply via email to