Details
-
Type:
Bug
-
Status: Closed (View Workflow)
-
Priority:
Major
-
Resolution: Won't Fix
-
Component/s: pipeline
-
Labels:
-
Similar Issues:
-
Epic Link:
Description
In a pipeline stage, it is not possible to reference a variable that is set inside a shell script as part of a former stage, see the simplified example below. In my use case, the first stage reads a file in the workspace and evaluates part of its content to set the variable.
stage 'Fetch version' sh '''#!/bin/sh version=abc''' stage 'Second' sh "${mvnHome}/bin/mvn -f all/pom.xml -Dversion=$version ...
Result:
groovy.lang.MissingPropertyException: No such property: version for class: WorkflowScript
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:25)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:17)
at WorkflowScript.run(WorkflowScript:48)
I've tried a lot of different things setting and accessing the variable, including the environment variable env, but nothing worked.
Use the `readFile` workflow function: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-readfile-code-read-file-from-workspace
I'm pretty sure the behavior necessary to make the script you're demonstrating work (either as pipeline variable, or shell variable) could have unexpected and impossible to debug side effects if implemented.