Skip to main content

Availability and Scope of Harness Variables

The variables used in Harness follow a naming convention that describes where they can be used. When you select a variable, it helps to understand the naming convention, as there might be numerous variables from which to choose.

For example, an account-level variable created in Account Defaults begins with the namespace account.defaults followed by the variable name. The reference for an Account Defaults variable named productName is ${account.defaults.productName}.

Whenever you have a Harness field that permits variables, begin by typing ${ and the variables available to that entity are displayed.

Naming Conventions

The following table lists the naming conventions for the different variable namespaces.

EntityPrefix NamespaceExamples
Account Defaultsaccount.defaults${account.defaults.productName}
Application Defaultsapp.defaults${app.defaults.MyApp}
Applicationapp${app.name}
Artifactartifact${artifact.displayName}
Serviceservice${service.name}, ${serviceVariable.``*variable\_name*``}
Environmentenv${env.description}
Workflowworkflow${workflow.lastGoodDeploymentDisplayName}
Infrastructure Definitioninfra${infra.name},${infra.route}, ${infra.kubernetes.namespace}, ${infra.pcf.route}
Instanceinstance${instance.hostName}
Approvalpublished_name, published_name.variables${published_name.approvedBy.email}, ​${published_name.variables.signoff}
EmailNA${toAddress}, ${ccAddress}, ${subject}, ${body}
Pivotal Cloud Foundrypcf${infra.pcf.route}
Kuberneteskubernetes${infra.kubernetes.namespace}

Multi-Phase Workflows and Variable Availability

If you are using a multi-phase Workflow, such as a Canary Workflow, certain expressions will only return results within the Phases in which their targets are set up and used.

For example, when you set up a Canary Workflow's Phase, you select an Infrastructure Definition and a Service. Expressions that refer to the Infrastructure Definition and Service, such as ${infra.name} and ${serviceVariable.foo}, will not return results outside of that Phase.

Using ${infra.name} and ${serviceVariable.foo} in the Pre-deployment Steps of the Workflow, which is before the Phases, will result in a bad substitution error.

Scope of Variables

Depending on the type of the variable, the scope and availability of variables can be defines as follows.

  • Service variables—Available wherever the Service is used. For example, in a multi-phase Workflow, the Service is selected when you set up the Phase, and therefore the Service variables are only available in the Phase.
  • Environment variables—Available in the Workflow and any Pipeline using that Workflow.
  • Infrastructure Definition variables—Available in the Workflow. For multi-phase Workflows, the Infrastructure Definition is selected when you set up the Phase, and therefore the Infrastructure Def variables are only available in the Phase.
  • Workflow variables—In the Workflow and Pipeline running the Workflow.