|
| 1 | +--- |
| 2 | +title:'How To: "Export" Variables From Child Pipeline' |
| 3 | +description: |
| 4 | +group:kb |
| 5 | +sub-group:articles |
| 6 | +toc:true |
| 7 | +kb:false |
| 8 | +ht:true |
| 9 | +common:false |
| 10 | +categories:[Pipelines, CLI] |
| 11 | +support-reviewed:2024-09-26 LG |
| 12 | +--- |
| 13 | + |
| 14 | +##Overview |
| 15 | + |
| 16 | +Below outlines a way you can capture variables from child pipelines in the parent pipeline. |
| 17 | + |
| 18 | +##Details |
| 19 | + |
| 20 | +The solution here is to use annotations[1] to capture the variables from child pipelines. Annotations are in plain text and should be considered non-confidential. |
| 21 | + |
| 22 | +###Child Pipeline |
| 23 | + |
| 24 | +Below is a step you can add at the end of the child pipeline to "export" the variables for the parent pipeline to access. |
| 25 | + |
| 26 | +```yaml |
| 27 | +setAnnotation: |
| 28 | +title:Set var on parent |
| 29 | +image:codefresh/cli |
| 30 | +commands: |
| 31 | + -PARENT=$(codefresh get -o json annotation workflow $CF_BUILD_ID cf_predecessor | jq .value) |
| 32 | + -echo "PARENT= $PARENT" |
| 33 | + -codefresh create annotation workflow $PARENT MY_VAR="my awesome value" |
| 34 | +``` |
| 35 | +
|
| 36 | +### Parent Pipeline |
| 37 | +
|
| 38 | +Below is a step you will use after the child pipeline completes to access the "exported" variable. This step uses the cf_export [2] to make the variable accessible in future steps. |
| 39 | +
|
| 40 | +```yaml |
| 41 | +displayAnnotation: |
| 42 | +title:setVar |
| 43 | +image:codefresh/cli |
| 44 | +commands: |
| 45 | + -cf_export My_VAR="$(codefresh get -o json annotation workflow $CF_BUILD_ID MY_VAR | jq .value)" |
| 46 | +``` |
| 47 | +
|
| 48 | +## Related Items |
| 49 | +
|
| 50 | +[1] [Annotations]({{site.baseurl}}/docs/pipelines/annotations/) |
| 51 | +
|
| 52 | +[2] [Exporting Variables]({{site.baseurl}}/docs/pipelines/variables/#exporting-environment-variables-from-a-freestyle-step) |