Is there an easy way to programmatically share a variable?

26 views
Skip to first unread message

Константин Ильченко

unread,
Feb 26, 2020, 11:03:52 AM2/26/20
to go-cd
Let's say I have this config:

format_version: 9

pipelines:
dummy:
group: Research
label_template: "${git[:8]}"
materials:
git:
branch: master
stages:
- build:
fetch_materials: true
jobs:
runner:
tasks:
- exec:
command: "/bin/sh"
arguments:
- "-c"
- "docker build --rm -t local/dummy:$GO_PIPELINE_LABEL ."
- deploy_stage:
jobs:
runner:
tasks:
- exec:
command: "/bin/sh"
arguments:
- "-c"
- "docker run -d -p '9900:3000' local/dummy:$GO_PIPELINE_LABEL"

On build stage I want to read a ./version file in some kind of a shared variable, like $VERSION, and use it instead of $GO_PIPELINE_LABEL on every other stage. Is this possible without creating and fetching artifacts?

Aravind SV

unread,
Feb 27, 2020, 4:08:05 AM2/27/20
to go...@googlegroups.com
On Wed, Feb 26, 2020 at 08:03:52 -0800, Константин Ильченко wrote:
> On *build* stage I want to read a ./version file in some kind of a shared
> variable, like $VERSION, and use it instead of $GO_PIPELINE_LABEL on every
> other stage. Is this possible without creating and fetching artifacts?

I assume you're looking for something more than: "source ./version; docker build --rm -t local/dummy:$GO_PIPELINE_LABEL ." ?

Typically, the only way to share information between stages is to use artifacts. External artifact plugins allow environment variables to be set, which affect other tasks within a job, but a standard artifact is probably the most straightforward way.

Cheers,
Aravind

Константин Ильченко

unread,
Feb 27, 2020, 5:08:14 AM2/27/20
to go-cd

I assume you're looking for something more than: "source ./version; docker build --rm -t local/dummy:$GO_PIPELINE_LABEL ." ?

Yes, the main point is to have a variable which is available on all stages (like a global one I guess), but is set up programmatically from one of stages.
 
Typically, the only way to share information between stages is to use artifacts. External artifact plugins allow environment variables to be set, which affect other tasks within a job, but a standard artifact is probably the most straightforward way. 

Thanks, this is exactly the answer to my question.
Reply all
Reply to author
Forward
0 new messages