Multiline variable gets truncated with cf_export
Exporting multiline variables to subsequent pipeline steps
Issue
Exporting a multi-line variable with cf_export
within a pipeline truncates the variable.
Running the pipeline in the example below, in the step test
the value of the variable is truncated and only line1
will appear.
version: "1.0"
steps:
assign:
image: alpine
commands:
- export TEST=`echo "line1" && echo "line2" && echo "line3"`
- echo $TEST
- cf_export TEST
test:
image: alpine
commands:
- echo $TEST
Every Codefresh pipeline has access to the that allows you to pass environment variables from [one step to the next].
Solution
Encode the variable with base64
to handle all special characters in the exported variable.
version: "1.0"
steps:
assign:
image: alpine
commands:
- apk add --update coreutils
- export TEST=`echo "line1" && echo "line2" && echo "line3"`
- echo $TEST
- cf_export TEST=`echo $TEST | base64 -w 0`
test:
image: alpine
commands:
- echo $TEST
- echo `echo $TEST | base64 -d`
If you run this pipeline, the test
step will correctly print line1 line2 line3
Related articles
cf_export utility in pipelines
Passing variables between steps
Troubleshooting common issues