Hi,
that is a confusing error in my point of view that you will learn to 
interpret :-) 

The pipeline you wrote is a declarative one and the usage of "def ... " is 
something you can do only in scripted pipelines ... hence, what the error 
really means is: "You forgot to open a script block".

The fix is just to wrap inside a "script" block that allow to execute 
scripted portion inside a declarative pipeline:

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

On Wednesday, 29 July 2020 22:04:44 UTC+1, Tom Brownridge 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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/21658d43-59e3-4619-96cc-f4d54ec86299o%40googlegroups.com.

Reply via email to