Hi guys,
In the field, I’ve run into a common question our customers have. How to take variables from one workflow and pass them on to another one.
Use Cases:
-
Passing in values from a Build Workflow leveraging Jenkins and using the outputs to populate configuration values in a Harness Workflow.
-
Developers are trying to pass in AWS attributes of a resource like ARN to a CloudFormation template.
-
Developers also want to leverage the outputs of a terraform provisioning workflow and passing it along into a JIRA ticket that updates throughout a service deployment.
Simple Walkthrough and Tutorial
Pre- Requisites
- 2 Harness Application Workflows
- 1 Harness Application Pipeline
Brief Walkthrough
-
Create a workflow, or leverage an existing workflow in your application
-
Click on ‘Add Command’ and select the ‘Shell Script Option’
-
Declare some variables in the shell script, in this case i did name, and last
name=rohan
export namelast=gupta
export last -
In the script outputs section, list out all the environment variables that you want to reference later on.
-
In the Publish Variable Name section, please provide the variable that you will leverage to call the ‘name’ or the ‘last’ variable
-
Set the scope to Pipeline so we can reference these variables in the second workflow in the Pipeline.
-
Hit Submit and it will add the shell script to the Workflow.
The Final Workflow should look like this for Workflow 1.
-
For Workflow 2, Create a Workflow 2 that has a shell script that echo’s out these variables.
-
The script should look like so:
echo ${context.info.name}
echo ${context.info.last} -
Hit Submit and Navigate over to the Pipeline section
Note: We use the ‘context’ variable to reference variables in context. This variable is a Harness variable. The ‘info’ variable is what you have assigned to reference the env variables name and last.
Workflow 2 Should look like so:
-
Create a Pipeline with two stages.
-
Add Stage 1, and select Workflow 1.
-
Add Stage 2, and select Workflow 2.
-
Deploy the Pipeline and review the execution logs.
Using this basic concept of Publishing Variables, teams can tackle a wide variety of use cases! If you guys have any cool uses cases to share, please share in the comments below!
Happy Thursday!
Rohan