cannot get build causes

21 views
Skip to first unread message

Tom Brownridge

unread,
Jul 29, 2020, 5:04:44 PM7/29/20
to Jenkins Users
Hello,

I am new and am fundamentally misunderstanding pipeline syntax and cannot relate the examples in the documentation. What am I missing?


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





Gianluca

unread,
Jul 30, 2020, 3:05:46 AM7/30/20
to Jenkins Users
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 {

Gavin Davies

unread,
Jul 30, 2020, 4:14:37 AM7/30/20
to jenkins...@googlegroups.com
Try nesting that in a script block 

pipeline {
    agent any
    stages {
        stage('example') {
            steps {
              script {
              }
            }
        }
    }
}

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/da7f2288-490d-40f5-ad6f-693ea3869bdbo%40googlegroups.com.


--
BackbaseGavin Davies
Senior System Engineer · R&D BA Cardiff Tribe · Cardiff
O +31 (0) 20 465 8888
LinkedIn · Twitter · Careers

Reply all
Reply to author
Forward
0 new messages