Jenkins: Variable in Pipeline-Phase kann nicht definiert werden

Ich versuche, ein deklaratives Jenkins-Pipeline-Skript zu erstellen, habe aber Probleme mit der einfachen Variablendeklaration.

Hier ist mein Skript:

pipeline {
   agent none
   stages {
       stage("first") {
           def foo = "foo" // fails with "WorkflowScript: 5: Expected a step @ line 5, column 13."
           sh "echo ${foo}"
       }
   }
}

Ich erhalte jedoch diesen Fehler:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: Expected a step @ line 5, column 13.
           def foo = "foo"
           ^

Ich bin auf Jenkins 2.7.4 und Pipeline 2.4.

Antworten auf die Frage(8)

Ihre Antwort auf die Frage