Computed Variables from one stage shared in other stages.

460 views
Skip to first unread message

munchrall

unread,
Oct 3, 2017, 7:24:37 PM10/3/17
to go-cd
Somewhat new to GO and I inherited our company's CICD system recently from someone who's no longer available to inquire, so please bare with me.

Our pipelines inherit from a Template that has 4 Stages

- Build
- DeployToDev
- DeployToTest
- DeployToProd

We utilize TFS as our respostory and use OctopusDeploy to deploy and promote our code.

Our build script creates a release / version number that is a composite of [ChangeSet].[BuildSystemVersionChangeSet].[%PipelineCounter%][%StepCounter]. This is all derived in the Build Stage and passed into the build script.

I need to retain this number somehow so that I can use it in the DeployToDev / DeployToTest / DeployToProd Stages in order to specify to OctopusDeploy which specific release / version needs to be promoted for that specific step.

Therefore, my question is what is the correct manner to store this value from the build stage for later stages, but only for that specific pipeline 'release'.

Any help is appreciated.

Darren Rowley

unread,
Oct 3, 2017, 10:24:01 PM10/3/17
to go-cd
Normally the easiest way to do this would be to generate the pipeline LABEL from these constructs and this label is available as an environment variable in every stage and the label can be carried forward through materials in upstream pipelines in the value stream. However because your label is generated as a side effect of artifacts in your build it is not currently possible in GoCd to update a label after a stage has started (https://github.com/gocd/gocd/issues/52).

So your other option is to take this label and output it to a file and then archive this file as an artifact of the first pipeline stage. Subsequent stages can then use the FetchArtifact task to fetch this artifact from previous stages (or even downstream pipelines in the VSM). Once you've fetched this file then you can use it directly or load it into an environment variable. Here's an example what the configration of your DeployToDev might look like (on linux) 

Tasks:

FetchArtifact:  pipeline Name: yourPipelineName pipeline Stage: build job Name: yourJob Source FIle buildLabel: /myDir/label.txt
CustomCommand: /bin/bash Arguments: -c export LABEL=$(cat ./label.txt) && ./octopusWhateverItDoes deploy $LABEL


Cheers,
D.

munchrall

unread,
Oct 24, 2017, 11:54:27 PM10/24/17
to go-cd
Darren,

Thank you for your assistance, it's given me a path forward and I appreciate it. As far as storing the text file content (build #) as an environment, do you have any documentation how to accomplish this? I'm in windows, and I have trouble understanding your bash example.

Thanks again,
munchrall

Darren Rowley

unread,
Oct 26, 2017, 4:30:08 PM10/26/17
to go-cd
I'm sorry I'm a windows muppet these days but I guess this will help?


thanks
D.
Reply all
Reply to author
Forward
0 new messages