Set Workflow Variables

Updated 1 week ago by Archana Singh

You can set variables in the Workflow Variables section of your Workflow, and use them in the Workflow step commands and settings.

New to Harness Variables? See What is a Harness Variable Expression?

You can also use them in some Harness Service settings in order to have their values replaced at the Workflow level.

You provide values for Workflow variables at deployment runtime for the Workflow or a Pipeline executing the Workflow.

In this topic:

Before You Begin

Review: Variable Types

There are several different types of Workflow variables you can add:

  • Entity—If you have parameterized a Workflow Service, Environment, or Infrastructure Definition setting, it will appear in Workflow Variables with the type ENTITY. See Templatize a Workflow.
  • Text—A text-based variable.
  • Email—Email addresses.
  • Number—Numeric variable.
Only Service Config Variables are added as environment variables and can be output with env. Workflow and other variables are not added as environment variables.

Review: Multi-Select Values

Currently, this feature is behind a Feature Flag. Contact Harness Support to enable the feature. Feature Flags can only be removed for Harness Professional and Essentials editions. Once the feature is released to a general audience, it's available for Trial and Community Editions.

See New features added to Harness and Features behind Feature Flags (Early Access) for Feature Flag information.

For Text and Email types, in Allowed Values, you can enter multiple options by separating them by commas.

For example:

When you deploy the Workflow, the values appear as a dropdown, with the Default Value already selected:

The same options will be available when the Workflow is used in a Pipeline and Trigger.

You can also search for values by simply entering the search values in the dropdown.

When you type into the dropdown to search for Allowed Values, be sure to select one or more values and not hit Enter. If you hit Enter, your search term will be used and if it is not exactly the same as an Allowed Value, it will fail during execution.

Step: Add Workflow Variables

To use Workflow variables, do the following:

  1. In a Workflow, click the pencil icon next to Workflow Variables. The Workflow Variables dialog appears.

Workflow Variables have the following settings.

Field

Description

Variable Name

Enter a name for the variable. When the variable is referenced elsewhere in you Harness application, the variable name is used.

Type

Select Text, Email, or Number.

If you have parameterized a Workflow Service, Environment, or Infrastructure Definition setting, it will appear in Workflow Variables with the type ENTITY.

Allowed Values

Enter a comma-separated list of values that users can select. The list will appear as a drop-down menu when the Workflow is deployed.

See Review: Multi-Select Values above.

You cannot template multi-value (drop-down) Allowed Values Workflow variables.

Default Value

Enter a value for the variable. A value is not mandatory.

Required

Select this option to enforce that a value for the variable is provided before the Workflow is executed.

Fixed

Select this option if the value of the variable specified here must not be changed.

Description

Provide a description of the variable that lets others know its purpose and requirements.

  1. In a Workflow step, use your variable by typing a dollar sign ($) and the first letter of your variable. The syntax for variable names is ${workflow.variables.name}.

Harness will load matching variable names.

For example, if you created a variable named Url, the variable name is ${workflow.variables.Url}.

When you deploy the Workflow, by itself or as part of a Pipeline, the variables are displayed in the Workflow execution step.

If the variables require values, you will enter the values when you add the Workflow to a Pipeline in the Stage settings or in the New Deployment setting when you deploy the Workflow individually.

Notes

Workflow variable expressions in Services — You can use Workflow variable expressions in a Harness Service, but Harness does not autocomplete Workflow variables in a Service like it does in a Workflow. You will need to manually enter the Workflow variable expression in the Service: ${workflow.variables.name}.

Next Steps


How did we do?