Multi-line variable gets truncated with cf_export
Exporting multi line variables to subsequent pipeline steps
Every Codefresh pipeline has access to the cf_export utility that allows you to pass environment variables from one step to the next.
Problem description
You have a pipeline that is trying to export a multi-line variable with cf_export
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
If you run this pipeline then in the step test
the value of the variable is truncated and only line1
will appear.
The solution
You can use a workaround by encoding the variable with base64
first. This will handle all strange 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