Use Harness expressions
For most settings in Harness pipelines, you can use fixed values, runtime inputs, or expressions.
You can use expressions (also called Harness expressions, variable expressions, or sometimes Harness variables) to reference Harness input, output, and execution variables. These variables represent settings and values that exist in the pipeline before and during execution. These can include environment variables, secrets, pipeline/stage/step identifiers, and more. You can also add your own variables and use expressions to reference them.
This topic explains how Harness expressions work, how to write and use expressions, some built-in Harness expressions, and some prefixes used to identify user-defined variables.
Expressions are powerful and offer many options for modification or interaction. For more information about using expressions, go to:
What is a Harness variable expression?
Harness variable expressions refer to variable values in Harness, such as entity names, configuration settings, custom variables, inputs/outputs, and more. At pipeline runtime, Harness evaluates any expressions present in the pipeline and replaces them with their resolved values.
For example, the expression <+pipeline.name>
resolves to name of the pipeline where you're using that expression.
Harness variables are powerful because they enable templatizing of configuration information, pipeline settings, values in scripts, and more. They also enable your pipelines to pass information between stages and settings.
Harness has many built-in variables and expressions, and you can define custom variables that you can reference with expressions. Custom variables can be broadly scoped (such as account-wide or project-wide variables) or narrowly scoped (such as a variable for a specific pipeline or stage). Custom variables can store values that you need to reuse across many entities, or they can help you configure a specific build, such as runtime flags and environment variables for certain build tools.
Additionally, certain step types, such as Run steps and Shell Script steps, can utilize and produce input, environment, and output variables that you define in the step settings. You can also reference these with expressions.
Expression usage
To reference Harness variables, you use expressions consisting of the expression delimiter <+...>
and a path to the referenced value, such as <+pipeline.name>
or <+secrets.getValue("SECRET_ID")>
.
In addition to Fixed Values and Runtime Inputs, you can use Harness expressions in many settings in pipelines and other entities, like connectors and triggers.
- Visual
- YAML
In the Visual Editor, you can use the Value type selector to select Expression.
Harness provides suggestions for built-in expressions as you type. You can manually trigger the suggestions by placing your cursor after <+
and pressing ctrl + space
.
In free-text fields, such as Command, you can directly enter values using the appropriate syntax without changing the value type.
You can continue typing or select the expression from the list of suggestions.
When writing pipelines in YAML, enter the expression as the value for a field.
For example, this connectorRef
setting takes it's value from an expression referencing a pipeline variable named myConnector
.
connectorRef: <+pipeline.variables.myConnector>
When you type <+
, Harness provides suggestions for built-in expressions as you type. You can manually trigger the suggestions by placing your cursor after <+
and pressing ctrl + space
.
You can continue typing or select the expression from the list of suggestions.
Automated suggestions don't represent all possible expressions.
When Harness automatically suggests expressions, it suggests expressions based on the current context (meaning the setting or place in the YAML where you are entering the expression). While it doesn't suggest expressions that aren't valid in the current context, this doesn't prevent you from entering invalid expressions.
For guidance on building valid expressions, go to Expression paths and Debugging expressions.
Expression paths
Harness expressions are references to variables, settings, and other values in Harness. When you use a Harness expression, you provide a path for Harness to follow to resolve the expression's value. Expressions can use relative paths or full paths (also referred to as FQNs).
Harness offers several ways to help you build expression paths:
Use FQNs
The format and length of an expression's Fully Qualified Name (FQN) depends on the type of entity the expression is referencing and where it is located.
Some expressions have short FQNs, such as <+account.name>
, which references your Harness account name, or <+variable.account.accountVariableName>
, which references a custom account variable. In contrast, expression referencing specific settings embedded a pipeline's YAML can have much longer FQNs, like this expression for a service variable in a CD stage: <+pipeline.stages.stageID.spec.serviceConfig.serviceDefinition.spec.variables.serviceVariableName>
.
When referencing values within a pipeline, an expression's FQN is the path to the value you are referencing in the context of your pipeline's YAML. For values in pipelines, the expression's full path/FQN, starting from pipeline
, always works as a reference point.
For example, the FQN for an expression referencing a CD service definition's imagePath
setting is <+pipeline.stages.stageID.spec.serviceConfig.serviceDefinition.spec.artifacts.primary.spec.impagePath>
. This reflects the path you would step through in the YAML to locate that value.
Use relative paths
To use a relative path, identify the common parent between the step/stage you're referring to and the step/stage where you're using the expression (making the reference), and then use the common parent to start the expression.
For example, to reference a CD service definition's imagePath
setting in the same stage where that service definition is defined, you could use the relative expression <+stage.spec.serviceConfig.serviceDefinition.spec.artifacts.primary.spec.impagePath>
.
Use expressions only after they can be resolved
When Harness encounters an expression during pipeline execution, it tries to resolve the expression with the information it has at that point in the execution. This means that if you try to use an expression before Harness has the necessary information to resolve the expression's value, the expression resolves to null
, and the pipeline can fail or execute incorrectly.
This requirement applies regardless of how you are using the expression, such as with operators or in scripts. If Harness can't resolve the target value at the point when the pipeline requests the expression, the expression fails to resolve and the pipeline can fail.
Your pipelines must use expressions only after Harness has the required information to resolve the expression's value.
For example, assume you want to use this expression: <+pipeline.stages.Stage_2.spec.execution.steps.Step_C.executionUrl>
. This expression calls the executionUrl
from a step named Step_C
that is in Stage_2
. Since this step is in Stage_2
, you could not use this expression in a previous stage, because the stage containing this expression's value hasn't run yet. Additionally, if there are steps before Step_C
in Stage_2
, those steps can't use this expression either, because they run before Step_C
.
Here are some guidelines to help you successfully use expressions in pipelines:
- Don't refer to a step's expressions within that same step.
- Don't refer to values from a subsequent step/stage in a step/stage that runs before the referenced step/stage.
- Don't refer to step inputs/outputs in a CD stage's Service or Environment configuration.
- In a CD stage, steps run after Harness evaluates the service and environment configuration. Consequently, Harness can't get values for expressions referencing step inputs/outputs while it is evaluating the service and environment configuration.
- Similarly, don't refer to step inputs/output in a CI stage's Infrastructure or Codebase configuration. These are evaluated before steps run, so they can't use expressions referencing steps.
Example: Harness expression resolution throughout a CD stage
This example demonstrates when and where certain expressions (by prefix) are resolved over the duration of a CD stage, so that you can determine which events need to occur before you can safely reference a certain expression and ensure that it is successfully resolved when the pipeline runs.
Here's when you can reference expressions resolved from information in each of these stage sections:
- Service expressions can be resolved only after Harness has progressed through the Service section of the pipeline. Consequently, you can use service expressions in the Infrastructure and Execution sections of the stage.
- Infrastructure expressions can be resolved only after Harness has progressed through the Infrastructure section of the pipeline.
- In the Infrastructure section, you can reference Service settings.
- Since Execution follows Infrastructure, you can reference Infrastructure expressions in Execution.
- Execution expressions apply to steps in Execution.
- Each step's Execution expressions can be referenced only after Harness has progressed through that step in the Execution section.

Hyphens require escaping
Harness recommends not using hyphens/dashes (-
) in variable and property names, because these characters can cause issues with headers and they aren't allowed in some Linux distributions and deployment-related software.
For example, this expression won't work: <+execution.steps.httpstep.spec.headers.x-auth>
If you must include a hyphen in an expression, such as with x-auth
, you can wrap the property name in double quotes (""
), such as <+execution.steps.httpstep.spec.headers["x-auth"]>
.
This also applies to nested usage, such as:
<+execution.steps.httpstep.spec.newHeaders["x-auth"]["nested-hyphen-key"]>
<+execution.steps.httpstep.spec.newHeaders["x-auth"].nonhyphenkey>
If when referencing custom variables or matrix dimensions with hyphenated names, you must use the get()
method.
Expression evaluation
Mechanically, Harness passes the content within the delimiter (<+...>
) to the Java Expression Language (JEXL) for evaluation at runtime.
For example, <+pipeline.name>
evaluates to the name of the pipeline where that expression is used.
Here's an example of a shell script echoing some expressions, along with examples of output from those expressions.
echo <+pipeline.executionId> # Output example: 1234-5678-abcd
echo <+pipeline.sequenceId> # Output example: 16
echo <+stage.name> # Output example: dev
echo <+service.name> # Output example: nginx
echo <+artifacts.primary.image> # Output example: index.docker.io/library/nginx:stable
echo <+artifacts.primary.imagePath> # Output example: library/nginx
echo <+env.name> # Output example: demo
echo <+infra.namespace> # Output example: default
echo <+infra.releaseName> # Output example: demo
Expressions can't resolve correctly if the target value isn't available at the time that Harness evaluates the expression. For more information, go to Use expressions after they can be resolved.
Additionally, variable values (after evaluation) are limited to 256 KB. Expressions producing evaluated values larger than this can have truncated values or fail to resolve.
Expression manipulation
In addition to standard evaluation, expressions can be evaluated and manipulated with Java string methods, JSON parsing, JEXL, interpolation, concatenation, and more.
Compound expressions and operators require nested delimiters
When forming complex expressions, such as when using operators or methods with expressions, wrap the entire compound expression statement in the expression delimiter (<+...>
).
For example, with the equals ==
and not equals !=
operators, wrap the entire operation in the expression delimiter <+...>
:
<+<+pipeline.name> == "pipeline1">
<+<+stage.variables.v1> != "dev">
Complex usage can have multiple levels of nesting. For example, the following compound expression concatenates values from two variables into one list, and then uses the split()
method on the concatenated list. The original expressions, the concatenated list expression, and the method manipulation are all wrapped in expression delimiters:
<+ <+<+pipeline.variables.listVar1> + "," + <+pipeline.variables.listVar2>>.split(",")>
Java string methods
You can use any Java string method on Harness expressions.
JEXL
You can use JEXL to build complex expressions.
For example, the following complex expression uses information from a webhook trigger payload:
<+ <+<+trigger.payload.pull_request.diff_url>.contains("triggerNgDemo")> || <+trigger.payload.repository.owner.name> == "wings-software" >
Notice the use of methods, operators, and nested delimiters (<+...>
) forming a compound expression. Harness evaluates each individual expression and produces a final value by evaluating the entire JEXL expression.
Ternary operators
When using ternary conditional operators (?:
), wrap the entire expression in the expression delimiter <+...>
, and don't use spaces between the operators and values.
Ternary operators in Harness follow the standard format, but you can't use spaces between the operators and values.
For example:
- Incorrect:
<+condition ? IF_TRUE : IF_FALSE>
- Correct:
<+condition?IF_TRUE:IF_FALSE>
Pipeline YAML example manipulating expressions with ternary operators
This pipeline uses a ternary operator to evaluate a stage variable named myvar
with a value of 1.1
.
In the second ShellScript
step, named ternary
, the stage variable is referenced by the expression <+stage.variables.myvar>
and evaluated with the ternary expression == "1.1"?"pass":"fail"
. The entire compound expression is <+ <+stage.variables.myvar> == "1.1"?"pass":"fail" >
.
pipeline:
name: exp
identifier: exp
projectIdentifier: CD_Docs
orgIdentifier: default
tags: {}
stages:
- stage:
name: ternarydemo
identifier: ternarydemo
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: ShellScript
name: ShellScript_1
identifier: ShellScript_1
spec:
shell: Bash
onDelegate: true
source:
type: Inline
spec:
script: echo <+stage.variables.myvar>
environmentVariables: []
outputVariables: []
timeout: 10m
- step:
type: ShellScript
name: ternary
identifier: ternary
spec:
shell: Bash
onDelegate: true
source:
type: Inline
spec:
script: echo <+ <+stage.variables.myvar> == "1.1"?"pass":"fail" >
environmentVariables: []
outputVariables: []
timeout: 10m
tags: {}
variables:
- name: myvar
type: String
description: ""
required: true
value: "1.1"
For more information about using ternary operators in Harness, go to Using Ternary Operators with Triggers.
Expressions as strings
If you want to treat an expression as a string, you wrap it in double quotes, with the exception of secrets expressions (such as <+secrets.getValue()>
) and some JSON usage.
For example, the following command has the expression <+stage.name>
wrapped in double quotes because it is an element in an array of strings.
<+<+pipeline.variables.changeType> =~ ["<+stage.name>","All"]>
When using expressions as strings in JSON, the entire expression must be wrapped in double quotes, if that is required to make the JSON valid.
For example, in the following JSON, the expression <+pipeline.variables.version>
must be wrapped in quotation marks because it resolves as a string in that part of the JSON. However, the expression <+<+pipeline.variables.hosts>.split(\",\")>
isn't wrapped in quotation marks because it resolves as a list.
"{\"a\":[ { \"name\": \"svc1\", \"version\": \"<+pipeline.variables.version>\", \"hosts\": <+<+pipeline.variables.hosts>.split(\",\")> } ]}"
Do not wrap <+secrets.getValue()>
expressions in double quotes. While the secret ID within the getValue()
method must be wrapped in double quotes, do not wrap the entire expression in double quotes, even when you want to treat it as a string.
This is because these expressions are resolved by an internal Secret Manager function. The value is not a primitive type string, and it must not be wrapped in double quotes.
For example, in the following complex expression, the <+secrets.getValue()>
expression is not wrapped in double quotes, despite being used in an operation where another expression would be wrapped in double quotes.
<+<+<+pipeline.variables.var1>=="secret1">?<+secrets.getValue("secret1")>:<+secrets.getValue("defaultSecret")>>
Concatenation and interpolation
Harness supports complex usages of string interpolation, such as:
- Substituting an expression value within a path:
us-west-2/nonprod/eks/eks123/<+env.name>/chat/
- Using an expression to supply the value of an identifier within another expression:
- This example uses the index of the looped execution to pick the desired step by ID:
<+stage.spec.execution.steps.s1<+strategy.identifierPostFix>.steps.ShellScript_1.output.outputVariables.v1>
- This example would print the status of a stage where the stage name is defined as a stage variable:
<+pipeline.stages.<+pipeline.variables.stageName>.status>
- This example uses the index of the looped execution to pick the desired step by ID:
Harness string variables can be concatenated by default. Each expression can be evaluated and substituted in the string.
Previously, you always used +
or concat()
to join multiple expressions together. Now, you can simply list the expressions with spaces between, for example:
<+pipeline.name> <+pipeline.executionId>
The concatenation operator (+
) and the concat()
method also work. Note that these options require you to wrap the entire operation in the expression delimiter (<+...>
). For example, the following syntax is valid:
<+<+pipeline.variables.var1> + "_suffix">
<+<+pipeline.variables.var1>.concat("_suffix")>
When concatenating expressions as strings, each expression must evaluate to a string.
If an expression does not satisfy this condition, use the toString()
method to convert it to a string.
For example, in /tmp/spe/<+pipeline.sequenceId>
the variable sequenceId
evaluates to an integer. When concatenating this with other string expressions, it must be converted to a string, such as: /tmp/spe/<+pipeline.sequenceId.toString()>
.
Input and output variables
Your pipelines, stages, and steps can ingest inputs and produce outputs. In general, input variables represent a pipeline's configuration — the settings and values defining how and where an execution runs. Output variables are the results of an execution — such as release numbers, artifact IDs, image tags, user-defined output variables, and so on.
You can use expressions to reference inputs and outputs. For example, you could reference a previous step's output in a subsequent step's command.
The expression to reference an input or output depends on the scope where it was defined and the scope where you're referencing it. Usually, the expression follows the YAML path to the setting, and the full path (starting from pipeline
) is always a valid reference. For example, to reference the command
setting for a Run step in a Build stage, you could use an expression like <+pipeline.stages.BUILD_STAGE_ID.spec.execution.steps.RUN_STEP_ID.spec.command>
. If you were referencing this setting in another step in the same stage, you could use a relative path like <+execution.steps.RUN_STEP_ID.spec.command>
.
Get input/output expressions from execution details
In a pipeline's execution details, you can explore inputs and outputs for the pipeline as a whole, as well as for individual steps.
From the execution details, you can quickly copy the expression to reference any step-level input or output.
This is useful for determining expression paths, when debugging expressions, or when you're not sure which expression to use for a particular setting or value.
To do this:
-
Go to the execution details page. You can get there by going to your Executions, Builds, or Deployments history and selecting the execution you want to inspect.
-
To inspect step-level inputs and outputs, select a step in the execution tree, and then select the Input and Output tabs.
For example, these are some inputs and outputs for a Kubernetes rollout deployment step:
-
To get the expression referencing a particular input/output, hover over the Input/Output Name and select the Copy icon.
For example, if you want to reference a Run step's Command setting, navigate to the Run step's Input on the execution details page, locate command under Input Name, and select the Copy icon. Your clipboard now has the expression for this Run step's command, such as
<+pipeline.stages.stageID.spec.execution.steps.RunStepID.spec.command>
.This example copies the podIP setting for a Kubernetes rollout deployment step, resulting in an expression such as
<+pipeline.stages.STAGE_ID.spec.execution.steps.STEP_ID.deploymentInfoOutcome.serverInstanceInfoList[0].podIP>
. -
In the same way, you can copy values tied to specific inputs and output. Copying a value copies the literal value, not the expression. To reference this value by an expression, you need to use the Copy option for the Input/Output Name.
Get custom variable and input expressions from the Variables list
You can get expressions for custom pipeline variables and execution inputs from the Variables list in the Pipeline Studio.

If the variable is local to a scope within the pipeline, such as a stage or step group, you can copy either the local, relative-path expression (to use the expression in the origin scope) or the full path/FQN expression (to use the expression outside the origin scope, such as in another stage).
Get input/output expressions used in a from execution context
The Execution Context provides information about resolved expressions and their values for each step in the Step Detail pane. Its purpose is to aid in debugging previous executions of the pipeline, serving as an additional tool alongside the Input/Output variables listed for each step.
Let's consider the following example:
pipeline:
name: pipeline
identifier: pipeline
projectIdentifier: docs_play
orgIdentifier: default
tags: {}
stages:
- stage:
name: custom
identifier: custom
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: ShellScript
name: ShellScript_1
identifier: ShellScript_1
spec:
shell: Bash
executionTarget: {}
source:
type: Inline
spec:
script: echo {$executionUrl}
environmentVariables:
- name: executionUrl
type: String
value: <+pipeline.executionUrl>
outputVariables: []
timeout: 10m
tags: {}
Execution context is a table of keys and values with keys being the expressions that were referred within the step. In the above example, in the step, ShellScript_1, we have defined an input/environment variable, executionUrl
with an expression type. Once you run the pipeline, click on the ShellScript_1 step and then select Execution Context in the Step Details pane.
You can also get the expressions for step level variable and execution inputs from Execution Context.
Some important points to note:
- Secrets are not displayed in the Execution Context.
- The Execution Context is non-editable, meaning you won't be able to add or remove items from it.
Expressions reference
The following sections describe some Harness expressions. This information is not exhaustive.
Account, org, and project expressions
<+account.identifier>
: The identifier for your Harness account.<+account.name>
: Your Harness account name.<+account.companyName>
: The company name associated with your Harness account.<+org.identifier>
: The identifier of an organization in your Harness account. The referenced organization depends on the context where you use the expression.<+org.name>
: The name of the organization.<+org.description>
: The description of the organization.<+project.identifier>
: The identifier of a Harness project in your Harness account. The referenced project depends on the context where you use the expression.<+project.name>
: The name of the Harness project.<+project.description>
: The description of the Harness project.<+project.tags>
: All Harness tags attached to the project.
Approval expressions
Whenever a user grants an approval in a Harness Manual Approval step, the pipeline maintains the user information of the approver for the rest of the pipeline execution. You can use these variables in notifications after an approval is granted.
These expressions apply to Harness Manual Approval steps only. They are not applicable to Approval stages or third-party approval steps (such as Jira or ServiceNow approval steps).
<+approval.approvalActivities[0].user.name>
: The Harness username of the approver.<+approval.approvalActivities[0].user.email>
: The email address of the approver.<+approval.approvalActivities[0].comments>
: User comments from the approval, formatted as a single string. This variable is populated from thecomment
output variable generated by the Approval step.
Use the index value to get information from different Approval steps in the same pipeline. For example, if you have a Deploy stage with two Approval steps, the pipeline maintains a separate set of approval variable values for each Approval step. Use the array index in the expressions to access the values for a specific approval.
CI codebase and environment variables
For information about variables and expressions relevant to Harness CI, go to:
Custom variables
For information about user-defined variables, including naming conventions, special handling, and other usage specifications, go to Define variables.
Deployment environment expressions
In Harness CD, environments represent your deployment targets (such as QA, Prod, and so on). Each environment contains one or more Infrastructure Definitions that list your target clusters, hosts, namespaces, and so on. You can use expressions to reference environment values, such as <+env.name>
, in a service's Values YAML file, specs, and config files, for example.
<+env.name>
: The name of the environment used in the current stage.<+env.identifier>
: The entity identifier of the environment used in the current stage.<+env.description>
: The description of the environment.<+env.type>
: The environment type, such asProduction
orPreProduction
.<+env.envGroupName>
: The name of the environment group to which the environment belongs, if defined. This expression resolves only if the deployment is done on an environment group.<+env.envGroupRef>
: The environment group reference. This expression resolves only if the deployment is done on an environment group.

Environment expressions are useful. For example, you can use them in Service steps, or you can use JEXL to evaluate them in conditional execution settings, such as <+env.type> != "Production"
.
Custom environment-level variables
You can define custom variables in your environment and service definitions, and you can use expressions to reference those custom variables.

Currently, there are two versions of services and environments, v1 and v2. Services and environments v1 are being replaced by services and environments v2.
To reference custom environment-level variables, use the expression syntax <+env.variables.variableName>
.
Deployment infrastructure expressions
These expressions refer to deployment infrastructure configurations. Infrastructure definitions are associated with a deployment environment and they represent the actual clusters, hosts, etc., where Harness deploys a service.
-
<+infra.name>
: The name of the infrastructure definition used in a pipeline stage. -
<+infra.infraIdentifier>
: The ID of the infrastructure definition used in a pipeline stage. -
<+infra.tags>
: The tags on a CD stage's infrastructure definition. To reference a specific tag use<+infra.tags.TAG_KEY>
. -
<+infra.connectorRef>
: The ID of the Harness connector used in the Deploy stage's infrastructure definition. -
<+infra.connector.name>
: The name of the Harness connector used in the infrastructure definition. -
<+infra.namespace>
: The namespace used in the infrastructure definition. -
<+infra.releaseName>
: The release name used in the infrastructure definition.
INFRA_KEY and INFRA_KEY_SHORT_ID
<+INFRA_KEY>
references the infrastructure key, which is a unique string that identifies a deployment target infrastructure.
The infrastructure key is a combination of serviceIdentifier
, environmentIdentifer
and set of values unique to each infrastructure definition implementation (Kubernetes cluster, etc.) hashed using SHA-1
. For example, in case of a Kubernetes Infrastructure, the infrastructure key is a hash of serviceIdentifier-environmentIdentifier-connectorRef-namespace
. The format is sha-1(service.id-env.id-[set of unique infra values])
.
<+INFRA_KEY_SHORT_ID>
is a shortened form of <+INFRA_KEY>
. The shortened form is obtained by removing all but the first six characters of the hash of the infrastructure key.
These expressions are literally <+INFRA_KEY>
and <+INFRA_KEY_SHORT_ID>
. These expressions use capital letters.
Infrastructure keys are typically used in the Release Name setting to add labels to release for tracking. For example, in the infrastructure definition of a deploy stage, the <+INFRA_KEY>
is used in the Release Name to give the release a unique name, such as release-<+INFRA_KEY>
.
When the deployment runs, Harness adds the release name as a label. For example, in a Kubernetes deployment, release-<+INFRA_KEY
might resolve as harness.io/release-name=release-2f9eadcc06e2c2225265ab3cbb1160bc5eacfd4f
.
...
Pod Template:
Labels: app=hello
deployment=hello
harness.io/release-name=release-2f9eadcc06e2c2225265ab3cbb1160bc5eacfd4f
Containers:
the-container:
Image: monopole/hello:1
...
With the INFRA_KEY
, Harness can track the release for comparisons and rollback.
To resolve issues experienced with Kubernetes and Native Helm deployments when using the long form release-<+INFRA_KEY>
, Harness now uses <+INFRA_KEY_SHORT_ID>
in the default expression that Harness uses to generate a release name for the resources in Kubernetes and Native Helm deployments. This means that the Release name field, in the Advanced section of the Cluster Details in the infrastructure definition is now pre-populated with release-<+INFRA_KEY_SHORT_ID>
.
Deployment instance expressions
The following instance expressions are supported in Secure Shell (SSH) deployments, WinRM deployments, and Custom deployments using Deployment Templates.
These deployments can be done on physical data centers, AWS, and Azure. The deployment target determines which expressions you can use.
- For Microsoft Azure, AWS, or any platform-agnostic Physical Data Center (PDC):
<+instance.hostName>
: The host/container/pod name where the microservice/application is deployed.<+instance.host.instanceName>
: Same as<+instance.hostName>
.<+instance.name>
: The name of the instance on which the service is deployed.
- For Microsoft Azure or AWS:
<+instance.host.privateIp>
: The private IP of the host where the service is deployed.<+instance.host.publicIp>
: The public IP of the host where the service is deployed.
To use instance expressions in pipelines, you must use a repeat looping strategy and identify all the hosts for the stage as the target.
repeat:
items: <+stage.output.hosts>
When you use an instance expression in your pipeline, such as in a Shell Script step, Harness applies the script to all target instances. You do not have to loop through instances in your script.
For examples, go to Run a script on multiple target instances.
Instance attributes in deployment templates
For Deployment Templates, you can use instance expressions to reference host properties defined in the Instance Attributes in the deployment template.
Instances collected by the mandatory instancename field can be referenced by the expressions <+instance.hostName>
, <+instance.host.instanceName>
, or <+instance.name>
.
To reference the other properties added to Instance Attributes, use the expression syntax <+instance.host.properties.PROPERTY_NAME>
. For example, if you added a property named artifact
, you could reference it with the expression <+instance.host.properties.artifact>
.
Kubernetes deployment expressions
HARNESS_KUBE_CONFIG_PATH
While this doesn't follow the typical Harness expression syntax, ${HARNESS_KUBE_CONFIG_PATH}
is an expression referencing the path to a Harness-generated kubeconfig file containing the credentials you provided to Harness. The credentials can be used by kubectl commands by exporting their value to the KUBECONFIG environment variable.
Harness only generates this kubeconfig file when a delegate is outside of the target cluster and is making a remote connection. When you set up the Kubernetes cluster connector to connect to the cluster, you select the Specify master URL and credentials option. The master URL and credentials you supply in the connector are put in the kubeconfig file and used by the remote delegate to connect to the target cluster.
Consequently, you can only use ${HARNESS_KUBE_CONFIG_PATH}
when you are using a delegate outside the target cluster and a Kubernetes cluster connector with the Specify master URL and credentials option.
If you are running the script using an in-cluster delegate with the Use the credentials of a specific Harness Delegate credentials option, then there are no credentials to store in a kubeconfig file since the delegate is already an in-cluster process.
You can use the ${HARNESS_KUBE_CONFIG_PATH}
expression in a Shell script step to set the environment variable at the beginning of your kubectl script, such as export KUBECONFIG=${HARNESS_KUBE_CONFIG_PATH}
. It cannot be used in other scripts such as a Terraform script.
For example:
## Get the pods in the default namespace
export KUBECONFIG=${HARNESS_KUBE_CONFIG_PATH} kubectl get pods -n default
## Restart a deployment object in the Kubernetes cluster
export KUBECONFIG=${HARNESS_KUBE_CONFIG_PATH}
kubectl rollout restart deployment/mysql-deployment
kubernetes.release.revision
You can use the expression <+kubernetes.release.revision>
to get the deployment revision number.
This expression requires delegate version 23.04.79106 or later.
You can use this expression:
- In the
values.yaml
file, OpenShift Params, and Kustomize Patches. - To reference the current Harness release number as part of your manifest.
- To reference versioned ConfigMaps and Secrets in custom resources and fields unknown by Harness.
Important: Users must update their delegate to version to use this expression.