Publish Variables

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

  1. Create a workflow, or leverage an existing workflow in your application

  2. Click on ‘Add Command’ and select the ‘Shell Script Option’

  3. Declare some variables in the shell script, in this case i did name, and last

    name=rohan
    export name

    last=gupta
    export last

  4. In the script outputs section, list out all the environment variables that you want to reference later on.

  5. In the Publish Variable Name section, please provide the variable that you will leverage to call the ‘name’ or the ‘last’ variable

  6. Set the scope to Pipeline so we can reference these variables in the second workflow in the Pipeline.

  7. Hit Submit and it will add the shell script to the Workflow.

The Final Workflow should look like this for Workflow 1.

  1. For Workflow 2, Create a Workflow 2 that has a shell script that echo’s out these variables.

  2. The script should look like so:

    echo {context.info.name} echo {context.info.last}

  3. 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:

  1. Create a Pipeline with two stages.

  2. Add Stage 1, and select Workflow 1.

  3. Add Stage 2, and select Workflow 2.

  4. 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

2 Likes

For other lazy copy-pasters like myself, the {} blocks needs a $ in front of them.

echo ${context.info.name} echo ${context.info.last}

Nice tutorial!

1 Like