Harness YAML Code Reference
This document describes the YAML code keys and values used in the Harness Manager code editor to describe Harness Services, Environments, Workflows, and other components.
For how-tos on using YAML in Harness, see Configuration as Code Overview.
For each YAML file described in this document, the default keys are listed with example values and commented descriptions, for example:
harnessApiVersion: '1.0' # The Harness API version number.
type: ACCOUNT_DEFAULTS # The ACCOUNT_DEFAULTS value identifies the file type.
defaults:
- name: myCompany # The default name for the account.
value: Product Harness Account # A description of the Harness account.
All files must have the .yaml file extension. The .yml extension is not supported.
Harness and YAML
Harness supports the YAML spec version 1.2. The YAML spec does not identify invalid characters, just the reserved characters # > -. As long as there are single or double quotes around a string, it is allowed by YAML; however, Harness has requirements for what values can be used for different YAML keys. The best way to test is to use the value in the UI and see if an error occurs.
Harness Code and Git Repositories
You can sync Harness YAML with your Git repo. You can sync individual Applications or your entire Harness configuration. For more information, see Configuration as Code.
What Code Is Required?
Unless mentioned, all default folders displayed in the Harness Manager code editor are required. The required files and YAML keys depend on your configuration. When in doubt, consult the Harness Manager UI and look for required fields, marked with as asterisk (*).
If you sync your Harness Application with a Git repo and then delete a required file in Git and sync with Harness, the file is not replaced by Harness.
Encrypted Information in YAML
By default, Harness encrypts secrets such as passwords, files, and keys in Amazon KMS. In the YAML, you will see something like this:
fileName: amazonkms:_A1B2C3D4E5
This is the KMS record for the secret that Harness has created and stored in the KMS vault. This record has the information needed to connect and retrieve the secret from KMS.
You can also set Harness to use other secrets managers, such as HashiCorp Vault and AWS Secrets Manager.
In the Harness UI, you can reference pre-existing secrets in Vault and AWS Secrets Manager using a path, as described in Referencing Existing Secrets.
HashiCorp Vault
For HashiCorp Vault, you can also use the Harness YAML editor to reference pre-existing secrets in Vault using a fully-qualified path, such as hashicorpvault://LocalVault/foo/bar/mysecret#mykey
. The scheme hashicorpvault://
is needed to distinguish a Vault secret from other secret references. It is followed by the name of the Vault secret manager. In the following example, LocalVault
:
RBAC and YAMl Editor in Harness Manager
Harness applies RBAC to the YAML Editor in Harness Manager.
The account and Application permissions configured in a Harness User Group determines what account and Application YAML is displayed in the YAML Editor.
See Managing Users and Groups (RBAC).
If you have synched your account or Application with Git, as described in Configuration as Code, your Git provider RBAC settings apply on the Git side.
Defaults.yaml for Account
The Defaults.yaml file describes the Harness account defaults. It contains the following fields:
harnessApiVersion: '1.0' # The Harness API version number. You cannot edit this value.
type: ACCOUNT_DEFAULTS # The ACCOUNT_DEFAULTS value identifies the file type.
defaults:
- name: myCompany # The default name for the account.
value: Product Harness Account # A description of the Harness account.
Harness API Version
You can edit harnessApiVersion
in any YAML file but it does not have any impact.
Applications
This folder contains all of the Harness applications in your Harness account. For more information on Applications, see Application Checklist.
Application folder
Each Harness Application is contained in a folder using its Application name.
Index.yaml for Application
The index.yaml file describes the Application.
harnessApiVersion: '1.0' # The Harness API version number. You cannot edit this value.
type: APPLICATION # The file type.
description: A sample To-Do List application # The description of the Application.
Defaults.yaml for Application
The Defaults.yaml file in an Application folder contains the Application-wide variables. For more information, see Variables and Expressions in Harness.
harnessApiVersion: '1.0' # The Harness API version number. You cannot edit this value.
type: APPLICATION_DEFAULTS # The file type.
defaults: # Application-wide variables collection.
- name: BACKUP_PATH # The environment variable for the backup path on the host running the Harness Delegate.
value: $HOME/${app.name}/${service.name}/${env.name}/backup/${timestampId}
- name: STAGING_PATH # The environment variable for the staging path on the host running the Harness Delegate.
value: $HOME/${app.name}/${service.name}/${env.name}/staging/${timestampId}
- name: RUNTIME_PATH # The environment variable for the runtime path on the host running the Harness Delegate.
value: $HOME/${app.name}/${service.name}/${env.name}/runtime
- name: WINDOWS_RUNTIME_PATH # The environment variable for the runtime path on the Windows host running the Harness Delegate.
value: '%USERPROFILE%\${app.name}\${service.name}\${env.name}\runtime'
Services
The folders and files under Services define each Harness Service used in the Application. For more information, see Add a Service.
Service Folder
Each Service in the Application is contained in a folder using its name, such as Harness Sample App. All folders and files that define the Service are contained in the Service's folder.
Index.yaml for Service
The primary file for the Service. Its contents depend on the Service type, such as Docker Image or JAR, and the configuration.
Here is an example a Index.yaml for a Docker Image Service:
harnessApiVersion: '1.0' # The Harness API version number.
type: SERVICE # The file type.
artifactType: DOCKER # The Service type.
configMapYaml: |- # The Kubernetes ConfigMap block.
kubectl describe configmaps my-config
Name: my-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
my.properties: 158 bytes
configVariables: # User-added config variables.
- name: foo
value: bar
valueType: TEXT
helmValueYaml: | # The Helm values.yaml block.
# Enter your Helm value YAML
# ---
namespace : ${NAMESPACE}
Deployment Specifications
This folder contains the Service-specific container specifications. For example, a Service that contains a Kubernetes Container Specification will display that specification in this folder.
A service that uses an ECS Container Specification and Service Specification will display those specs in this folder.
Here is a Kubernetes Container Specification with the default comments removed:
harnessApiVersion: '1.0' # The Harness API version number.
type: KUBERNETES # The Deployment Specification type.
advancedConfig: | # This block contains the Kubernetes deployment specification.
# Enter your Controller YAML spec below.
# ---
apiVersion: "extensions/v1beta1"
kind: "Deployment"
metadata:
annotations: {}
finalizers:
labels: {}
ownerReferences:
spec:
replicas: 0
template:
metadata:
annotations: {}
finalizers:
labels: {}
ownerReferences:
spec:
containers:
- args:
command:
env:
envFrom:
image: "${DOCKER_IMAGE_NAME}"
name: "${CONTAINER_NAME}"
ports:
volumeMounts:
hostAliases:
imagePullSecrets:
- name: "${SECRET_NAME}"
initContainers:
nodeSelector: {}
tolerations:
volumes:
Artifact Servers
This folder contains the Artifact Sources for the Service. Here is an Artifact Source that uses an SFTP Artifact Server to obtain files matching the regex pattern Downloads\todo*.*zip:
harnessApiVersion: '1.0' # The Harness API version number.
type: SFTP # The Artifact Source type.
artifactPaths: # The artifact path on the SFTP server.
- Downloads\todo*.*zip # Regex path.
metadataOnly: true # Harness will only obtain metadata for the artifact.
serverName: SFTP-Local # The name of the Artifact Server selected.
Here is an Artifact Source that uses a Docker Registry Artifact Server to obtain an Nginx artifact:
harnessApiVersion: '1.0' # The Harness API version number.
type: DOCKER # The Artifact Source type.
imageName: library/nginx # The Docker image registry and image name.
metadataOnly: true # Harness will only obtain metadata for the artifact.
serverName: registry_hub_docker_com # The name of the Artifact Server selected.
Commands
This folder contains the scripts for commands that are in the Service, such as Bash and PowerShell scripts. Here is an example of some common scripts:
Here is the code for the Install.yaml file that contains the Install script:
harnessApiVersion: '1.0'
type: OTHER
commandUnitType: COMMAND
commandUnits:
- command: echo "this is an exec command"
commandUnitType: EXEC
deploymentType: SSH
name: Exec
scriptType: BASH
workingDirectory: dir
- artifactVariableName: artifact
commandUnitType: SCP
deploymentType: SSH
destinationDirectoryPath: $WINGS_RUNTIME_PATH
name: SCP
source: ARTIFACTS
- command: |2-
# Execute as root and pass environment variables
# su -p -
# Execute as root via user credentials (with root privileges)
# sudo -E su -p -
# The following variables are absolute paths defined as:
# ${HOME}/${appName}/${serviceName}/${serviceTemplateName}/[runtime|backup|staging]
mkdir -p "$WINGS_RUNTIME_PATH"
mkdir -p "$WINGS_BACKUP_PATH"
mkdir -p "$WINGS_STAGING_PATH"
commandUnitType: SETUP_ENV
deploymentType: SSH
name: Setup Env
scriptType: BASH
workingDirectory: dir
- command: |-
docker login --username="$DOCKER_USER_ID" --password="$DOCKER_USER_PASSWORD"
docker run -d -it "$DOCKER_IMAGE"
docker logout
commandUnitType: DOCKER_START
deploymentType: SSH
name: Docker Start
scriptType: BASH
- command: docker ps -a -q --filter ancestor=$IMAGE | xargs docker stop
commandUnitType: DOCKER_STOP
deploymentType: SSH
name: Docker Stop
scriptType: BASH
- artifactVariableName: artifact
commandUnitType: DOWNLOAD_ARTIFACT
deploymentType: SSH
name: Download Artifact
scriptType: BASH
workingDirectory: ${app.defaults.RUNTIME_PATH}
- command: |-
set -x
pgrep -f "\-Dcatalina.home=$WINGS_RUNTIME_PATH/tomcat"
commandUnitType: PROCESS_CHECK_RUNNING
deploymentType: SSH
name: Process Running
scriptType: BASH
- command: |-
set -x
pgrep -f "\-Dcatalina.home=$WINGS_RUNTIME_PATH/tomcat"
rc=$?
if [ "$rc" -eq 0 ]
then
exit 1
fi
commandUnitType: PROCESS_CHECK_STOPPED
deploymentType: SSH
name: Process Stopped
scriptType: BASH
- command: |-
set -x
nc -v -z -w 5 localhost 8080
rc=$?
if [ "$rc" -eq 0 ]
then
exit 1
fi
commandUnitType: PORT_CHECK_CLEARED
deploymentType: SSH
name: Port Cleared
scriptType: BASH
- command: |-
set -x
nc -v -z -w 5 localhost 8080
commandUnitType: PORT_CHECK_LISTENING
deploymentType: SSH
name: Port Listening
scriptType: BASH
targetToAllEnv: true
Template Library Commands
The Commands folder displays different YAML keys to indicate that a script is linked from the Template Library. For example, the following script named JSON to Environment Variables is linked to the JSON to Environment Variables script in the Template Library:
Here is the YAML for the script:
harnessApiVersion: '1.0' # The Harness API version number.
type: START # The script type.
commandUnitType: COMMAND # This is a Linux command.
commandUnits: # Linux command units. The grep and subsequent commands and printed on one line.
- command: grep -Eo '.*:.*?[^\\]"' ${ArtifactFileName} | sed 's/\"//g' | awk -F':' '{print "export " $1 "=\"" $2 "\""}' > __dummy.sh && . ./__dummy.sh && rm __dummy.sh
commandUnitType: EXEC # Exec command unit.
deploymentType: SSH # Remote machine execute.
name: Exec # The name of the command in the GUI.
scriptType: BASH # Script language.
workingDirectory: $RuntimePath # Environment variable.
targetToAllEnv: true # Apply to all Harness Environments.
# The following path is the location of the template in the user's Template Library
templateUri: johndoe/Generic Commands/Json to Environment Variables:latest
templateVariables: # Variable used in the template
- name: RuntimePath
value: foo
- name: ArtifactFileName
value: bar
Config Files
This folder contains the files added to the Config Files section of a Service. Here is an example with a text file and an encrypted PDF file.
Here is an example of the YAML file for an encrypted file in Config Files:
harnessApiVersion: '1.0' # The Harness API version number.
type: CONFIG_FILE # The YAML file type.
checksumType: MD5 # The hash function type.
description: encrypted-file-example # The description provided by the user.
encrypted: true # Encrypted file boolean value.
fileName: amazonkms:_gzC7yG5RAaC4kZNafymow # Harness KMS encryptedRecords entry used to decrypt file.
targetFilePath: encrypted-config-file-example.enc # The original filename.
targetToAllEnv: true
Environments
The folders and files under Environments define each Harness Environments used in the Application. For more information, see Add an Environment.
Environments Folder
Each Environment in the Application is contained in a folder using its name, such as QAEnv. All folders and files that define the Environment are contained in the Environment's folder.
Index.yaml for Environment
The primary file for an Environment. Here is a sample Index.yaml for a Non-Production Environment:
harnessApiVersion: '1.0' # The Harness API version number.
type: ENVIRONMENT # The file type.
environmentType: NON_PROD # The Environment type.
Variable Overrides and, in the case of Kubernetes, ConfigMap YAML Overrides, are stored in the Index.yaml file. For example, here is a Service Configuration Overrides section of an Environment that contains simple Variable Overrides and ConfigMap YAML Overrides entries:
The Index.yaml example we used above now includes these variable overrides, highlighted below:
harnessApiVersion: '1.0'
type: ENVIRONMENT
configMapYamlByServiceTemplateId:
tRmkVK3yQieFTlXrWqe7Cg: '# configMap Override'
environmentType: NON_PROD
variableOverrides: # Override Variables
- name: foo # Configuration variable name.
serviceName: MyService # Service for the overridden variable.
value: foo-override
valueType: TEXT # Text type.
- name: SecretVar # Configuration variable name.
serviceName: JAR-service # Service for the overridden variable.
value: amazonkms:2St-1zmsTeWFBtNqVqZvkg # Harness KMS encryptedRecords entry used to decrypt value.
valueType: ENCRYPTED_TEXT # Encrypted text type.
Infrastructure Definition
The Infrastructure Definition file is named with the Infrastructure Definition name and describes the Infrastructure Definition settings.
harnessApiVersion: '1.0'
type: INFRA_DEFINITION
cloudProviderType: AWS
deploymentType: AWS_LAMBDA
infrastructure:
- type: AWS_AWS_LAMBDA
cloudProviderName: aws_playground
iamRole: arn:aws:iam::448640225317:role/service-role/TestAwsLamdaRole
region: us-east-1
securityGroupIds:
- sg-05e7b8b9cad94b393
subnetIds:
- subnet-05788710b1b06b6b1
- subnet-0c945c814c09c9aed
vpcId: vpc-00a7e8ea4fd1ffd9d
scopedServices:
- AWS Lambda
The scopedServices section lists the Harness Services that can use this Infrastructure Definition. Each Service must be entered on a new like, like this:
scopedServices:
- AWS Lambda
- Lambda Example
Service Verification
The files in this folder are for the 24/7 Service Guard Overview verification configurations. Each configuration has its own file. Here is an example of a 24x7 Service Guard verification:
harnessApiVersion: '1.0' # The Harness API version number.
type: ELK # The Verification Provider type.
alertEnabled: false # Boolean value for enabling the alerts.
alertThreshold: 0.5 # Threshold value to reach for triggering the alerts.
baselineEndMinute: -1 # End time for baseline data.
baselineStartMinute: -1 # Start time for baseline data.
connectorName: ELK # Name of the Connector.
enabled24x7: false # Boolean value for enabling the settings.
hostnameField: host # Name of the host for which you want logs.
index: filebeat-* # Index value to search.
messageField: message # The field by which messages are usually indexed.
query: '*exception_____*' # The API Query required to retrieve the metric value.
serviceName: Kub_ser1 # Name of the Service.
timestampField: '@timestamp' # Timestamp field in the Elasticsearch record.
timestampFormat: yyyy-MM-dd'T'HH:mm:ss.SSSX # Format for the timestamp field in the Elasticsearch record.
Config Files
File Overrides in the Service Configuration Overrides of an Environment are listed in the Config Files folder. Here is a File Override in the UI:
The YAML file added for each File Override is named the same as the variable name. Here is the YAML in the file named after the variable, bar.yaml:
harnessApiVersion: '1.0' # The Harness API version number.
type: CONFIG_FILE_OVERRIDE # The type of override.
checksumType: MD5 The hash function type.
encrypted: false # Boolean for whether the file in encrypted.
fileName: bar # Name of the Service file to override.
serviceName: MyService # Name of the Service containing the file to override.
targetFilePath: bar # The file path or name of the file overridden.
Values
The Service Configuration Overrides for ConfigMap YAML Overrides and Helm Values YAML Overrides are listed in the Values folder, under a Services folder, followed by a folder named using the Service name.
The ConfigMap YAML Overrides is named Index.yaml. Here is an example:
harnessApiVersion: '1.0' # The Harness API version number.
type: APPLICATION_MANIFEST_VALUES_ENV_SERVICE_OVERRIDE # Type of override.
storeType: Local # Where the file is stored. Local means the Harness Data Store.
The values for the ConfigMap YAML Overrides are located in the Index.yaml for the Environment, as described in Index.yaml for Environment.The Helm Values YAML Overrides is named values.yaml, and simply contains a Helm values.yaml file contents, for example:
# Helm values override
harness:
helm:
chart:
name: nginx
version: 1.0.1
url: https://charts.bitnami.com/bitnami
Workflows
This folder contains all Workflows for the Application. Each Workflow is in its own YAML file named after the Workflow name. Workflow YAML files have different key-value pairs depending on their configuration. We include to simple examples below. The order of the YAML does not always reflect the order of Workflow steps, commands, or deployment operations.
Here is the UI of a Basic Workflow of SSH deployment type:
Below is the Workflow YAML for the Basic Workflow SSH deployment type with all of its sections collapsed. Each section is discussed later in the document.
harnessApiVersion: '1.0' # The Harness API version number.
type: BASIC # The Workflow type.
description: This is the workflow description. # Workflow description.
envName: QAEnv # Environment used by the Workflow.
failureStrategies: # Failure Strategy
- executionScope: WORKFLOW
notificationRules: # Notification Strategy
- conditions:
phases: # Workflow Steps
- type: SSH # Deployment Type, SSH.
preDeploymentSteps: # Pre-deployment check for Service artifacts.
- type: ARTIFACT_CHECK
rollbackPhases: # Rollback Steps.
- type: SSH
templatized: false # Identifies in the Workflow is templatized.
userVariables: # Workflow variables.
- type: TEXT
The following sections describe the YAML for each of the Workflow sections.
Pre-Deployment Steps
Pre-deployment steps are simple checks for artifacts in Basic Workflows. Here is an example of pre-deployment steps for the Basic Workflow with SSH deployment type:
preDeploymentSteps:
- type: ARTIFACT_CHECK
name: Artifact Check
Basic Workflow Phases
Workflows deployment steps are are broken into phases. A Basic Workflow is one phase. A Canary Workflow can be two or more phases.
Here is an example of a single phase in a Basic Workflow SSH deployment type. It contains a Select Nodes and a Jenkins step:
phases:
- type: SSH
computeProviderName: aws-docs-vars
daemonSet: false
infraDefinitionName: amazon web services- aws-docs-vars - AWS - us-east-1
name: Phase 1
phaseSteps:
- type: INFRASTRUCTURE_NODE
name: Prepare Infra
steps:
- type: AWS_NODE_SELECT
name: Select Nodes
properties:
excludeSelectedHostsFromFuturePhases: true
instanceCount: 3
instanceUnitType: COUNT
specificHosts: false
stepsInParallel: false
- type: DISABLE_SERVICE
name: Disable Service
stepsInParallel: false
- type: DEPLOY_SERVICE
name: Deploy Service
steps:
- type: JENKINS
name: Jenkins
properties:
jenkinsConfigId: Ze7ZvAFtSHOuDB5U_0wTQQ
jobName: HarshJenkins/harshjain12-patch-1
jobNameAsExpression: false
jobParameters: null
sweepingOutputName: null
sweepingOutputScope: null
timeoutMillis: 600000
stepsInParallel: false
- type: ENABLE_SERVICE
name: Enable Service
stepsInParallel: false
- type: VERIFY_SERVICE
name: Verify Service
stepsInParallel: false
- type: WRAP_UP
name: Wrap Up
stepsInParallel: false
provisionNodes: false
serviceName: SSH
statefulSet: false
preDeploymentSteps:
- type: ARTIFACT_CHECK
name: Artifact Check
rollbackPhases:
- type: SSH
computeProviderName: aws-docs-vars
daemonSet: false
infraDefinitionName: amazon web services- aws-docs-vars - AWS - us-east-1
name: Rollback Phase 1
phaseNameForRollback: Phase 1
phaseSteps:
- type: DISABLE_SERVICE
name: Disable Service
phaseStepNameForRollback: Enable Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: STOP_SERVICE
name: Stop Service
phaseStepNameForRollback: Deploy Service
statusForRollback: SUCCESS
steps:
- type: COMMAND
name: Stop
properties:
commandName: Stop
stepsInParallel: false
- type: DEPLOY_SERVICE
name: Deploy Service
phaseStepNameForRollback: Deploy Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: ENABLE_SERVICE
name: Enable Service
phaseStepNameForRollback: Disable Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: VERIFY_SERVICE
name: Verify Service
phaseStepNameForRollback: Deploy Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: WRAP_UP
name: Wrap Up
stepsInParallel: false
provisionNodes: false
serviceName: SSH
statefulSet: false
templatized: false
Canary Workflow Phases
Canary Workflows typically use two phases. The first phase deploys the microservice is a small number of instances and, once successful, the microservice is deployed to all instances.
Here is the first phase of a Canary Workflow of Kubernetes deployment type in the UI:
Here is an example of the two phases of a Canary Workflow of Kubernetes deployment type:phases:
harnessApiVersion: '1.0'
type: CANARY
concurrencyStrategy: INFRA
envName: prod
failureStrategies:
- executionScope: WORKFLOW
failureTypes:
- APPLICATION_ERROR
repairActionCode: ROLLBACK_WORKFLOW
retryCount: 0
notificationRules:
- conditions:
- FAILED
executionScope: WORKFLOW
notificationGroupAsExpression: false
userGroupAsExpression: false
userGroupIds:
- 1ZUJQSLVQky0eXumi1yHzQ
phases:
- type: KUBERNETES
computeProviderName: Harness Sample K8s Cloud Provider
daemonSet: false
infraDefinitionName: To-Do List K8s
name: CANARY
phaseSteps:
- type: K8S_PHASE_STEP
name: Deploy
steps:
- type: K8S_CANARY_DEPLOY
name: Canary Deployment
properties:
instanceUnitType: COUNT
instances: '1'
stepsInParallel: false
- type: K8S_PHASE_STEP
name: Verify
stepsInParallel: false
- type: K8S_PHASE_STEP
name: Wrap Up
steps:
- type: K8S_DELETE
name: Canary Delete
properties:
instanceUnitType: COUNT
resources: ${k8s.canaryWorkload}
stepsInParallel: false
provisionNodes: false
serviceName: To-Do List K8s
statefulSet: false
- type: KUBERNETES
computeProviderName: Harness Sample K8s Cloud Provider
daemonSet: false
infraDefinitionName: To-Do List K8s
name: Primary
phaseSteps:
- type: K8S_PHASE_STEP
name: Deploy
steps:
- type: K8S_DEPLOYMENT_ROLLING
name: Rollout Deployment
stepsInParallel: false
- type: K8S_PHASE_STEP
name: Verify
stepsInParallel: false
- type: K8S_PHASE_STEP
name: Wrap Up
stepsInParallel: false
provisionNodes: false
serviceName: To-Do List K8s
statefulSet: false
rollbackPhases:
- type: KUBERNETES
computeProviderName: Harness Sample K8s Cloud Provider
daemonSet: false
infraDefinitionName: To-Do List K8s
name: Rollback CANARY
phaseNameForRollback: CANARY
phaseSteps:
- type: K8S_PHASE_STEP
name: Deploy
phaseStepNameForRollback: Deploy
statusForRollback: SUCCESS
stepsInParallel: false
- type: K8S_PHASE_STEP
name: Wrap Up
phaseStepNameForRollback: Wrap Up
stepsInParallel: false
provisionNodes: false
serviceName: To-Do List K8s
statefulSet: false
- type: KUBERNETES
computeProviderName: Harness Sample K8s Cloud Provider
daemonSet: false
infraDefinitionName: To-Do List K8s
name: Rollback Primary
phaseNameForRollback: Primary
phaseSteps:
- type: K8S_PHASE_STEP
name: Deploy
phaseStepNameForRollback: Deploy
statusForRollback: SUCCESS
steps:
- type: K8S_DEPLOYMENT_ROLLING_ROLLBACK
name: Rollback Deployment
stepsInParallel: false
- type: K8S_PHASE_STEP
name: Wrap Up
phaseStepNameForRollback: Wrap Up
stepsInParallel: false
provisionNodes: false
serviceName: To-Do List K8s
statefulSet: false
templatized: false
Failure Strategy
The Failure Strategy YAML describes the steps Harness will take when a Workflow deployment fails and meets the Failure Strategy criteria.
Here is what the default Failure Strategy looks like in the UI:
Here is the YAML for the default Failure Strategy:
failureStrategies: # Failure Strategy settings.
- executionScope: WORKFLOW
failureTypes:
- APPLICATION_ERROR # Default strategy.
repairActionCode: ROLLBACK_WORKFLOW
retryCount: 0
Here is another Failure Strategy with all Failure Criteria selected:
- executionScope: WORKFLOW
failureTypes:
- CONNECTIVITY
- AUTHENTICATION
- VERIFICATION_FAILURE
- APPLICATION_ERROR
repairActionCode: ROLLBACK_WORKFLOW
retryCount: 0
Notification Strategy
The Notification Strategy describes which Harness Users and/or Groups to notify when a Workflow has failed, succeeded, or reached other criteria.
Here is the default Notification Strategy in the UI:
Here is the YAML for the default Notification Strategy:
notificationRules: # Notification Strategy settings.
- conditions:
- FAILED # Default strategy.
executionScope: WORKFLOW
notificationGroupAsExpression: false
notificationGroups:
- Account Administrator # User to notify.
Rollback Steps
The following are Rollback steps in case of a deployment failure or if rollback is part of a Failure Strategy. Here are the Rollback steps in the UI:
Here is the YAML for the Rollback Steps:
rollbackPhases:
- type: SSH # Execute on target host.
computeProviderName: local # Cloud Provider name.
daemonSet: false # Used by Kubernetes Workflow type only, hence false.
infraDefinitionName: Physical Data Center- local-DataCenter_SSH # Environment Infrastructure Definition used.
name: Rollback Phase 1
phaseNameForRollback: Phase 1
phaseSteps:
- type: DISABLE_SERVICE
name: Disable Service
phaseStepNameForRollback: Enable Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: STOP_SERVICE
name: Stop Service
phaseStepNameForRollback: Deploy Service
statusForRollback: SUCCESS
steps:
- type: COMMAND
name: Stop
properties:
commandName: Stop
stepsInParallel: false
- type: DEPLOY_SERVICE
name: Deploy Service
phaseStepNameForRollback: Deploy Service
statusForRollback: SUCCESS
steps:
- type: COMMAND
name: Install
properties:
commandName: Install
stepsInParallel: false
- type: ENABLE_SERVICE
name: Enable Service
phaseStepNameForRollback: Disable Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: VERIFY_SERVICE
name: Verify Service
phaseStepNameForRollback: Deploy Service
statusForRollback: SUCCESS
stepsInParallel: false
- type: WRAP_UP
name: Wrap Up
stepsInParallel: false
provisionNodes: false
serviceName: JAR-service
statefulSet: false # Used by Kubernetes Workflow type only, hence false.
Verification Steps
Verification Steps are used to apply Harness Continuous Verification to your deployment. Here is a Splunk Verification Step in the UI:
Here is the YAML for the same step:
- type: VERIFY_SERVICE # Workflow section type.
name: Verify Service # Workflow section name in UI.
steps:
- type: SPLUNKV2 # Verification step type.
name: Splunkv2 # Verification step name in UI.
properties: # Settings for the Splunk step.
hostnameTemplate: ${host.hostName} # Expression for the target hostname label in JSON.
analysisServerConfigId: nxaEMN00SXa0Y8X5woZCQA # Verification Provider ID.
query: '*exception*' # Query for the term exception.
analysisTolerance: MEDIUM # Algorithm Sensitivity is Moderate.
comparisonStrategy: COMPARE_WITH_PREVIOUS # Baseline for risk analysis.
executeWithPreviousSteps: true # Run in parallel with previous Verify Service steps.
hostnameField: host # JSON label for host/container.
timeDuration: '15' # Analysis time duration in minutes
Workflow Variables
Here is an example of a Workflow variable in the UI:
Here is the YAML for the variable:
userVariables:
- type: TEXT # Type of variable. Number and email are also supported.
description: My variable. # Description, but not value.
fixed: true # Boolean for if the var is Fixed and will not be changed.
mandatory: true # Boolean for required variable that must be used for the Workflow to deploy.
name: foo # Variable name.
value: bar # Variable value.
Common Workflow Commands
The Workflow commands you use varies according to your Workflow and deployment type, but there are some common commands that are used by most Workflows.
The following YAML lists examples for common commands:
Barrier:
- type: BARRIER # Command type.
name: Barrier # Name of command in UI.
properties:
identifier: deploy-checkout-and-shop # Barrier name, used by all related Barriers in other Workflows.
timeoutMillis: 600000 # Timeout for Barrier waiting for other Workflow Barriers.
HTTP: You can link to or copy the HTTP command template from the Template Library. Here is the YAML for a copied HTTP template:
- type: HTTP # HTTP command type.
name: HTTP # Name of command in the UI.
properties:
method: GET # HTTP request method.
socketTimeoutMillis: 10000 # Period to wait between packets before timing out.
header: 'content-type: application/json' # Content-Type entity header.
assertion: ${httpResponseCode}==200 # HTTP response code to check for.
executeWithPreviousSteps: false
url: http://app.example.io # The URL for the HTTP request.
Here is the YAML for a linked HTTP template:
- type: HTTP # HTTP command type.
name: Health Check # Name of the command in the UI.
properties:
method: GET # HTTP request method.
socketTimeoutMillis: 10000 # Period to wait between packets before timing out.
header: 'content-type: application/json' # Content-Type entity header.
assertion: ${httpResponseCode}==${ResponseCode} # HTTP response code compared to value below.
executeWithPreviousSteps: false
url: ${Url} # The URL variable for the HTTP request, value below.
templateUri: JohnDoe/HTTP Verifications/Health Check:latest # Template location in Template Library.
templateVariables: # Variables used in linked template.
- name: Url # Variable name, referenced above.
value: http://app.example.io # URL for variable.
- name: ResponseCode # Variable name, referenced above.
value: '200' # Response code value.
Approval:
- type: APPROVAL # Approval command type.
name: Approval # Name of command in UI.
properties:
userGroups:
- WA3Al7jsQ3a5IF-_yjsf_Q # ID of User Group for approval.
timeoutMillis: 1800000 # How long to wait for approval before failing.
Start, Stop, Install. These three common commands are grouped because their YAML is basically the same and there is little configuration in the UI or YAML.
- type: COMMAND # Step type.
name: Start # Name of command in the UI.
properties:
commandName: Start # Command name in Harness.
- type: COMMAND # Step type.
name: Stop # Name of command in the UI.
properties:
commandName: Stop # Command name in Harness.
- type: COMMAND # Step type.
name: Install # Name of command in the UI.
properties:
commandName: Install # Command name in Harness.
Triggers with Workflows
If you rename a Workflow in Git and sync that change with Harness, Triggers are maintained because a duplicate Workflow is created.
Pipelines
This folder contains all Pipelines for the Application. Each Pipeline is in its own YAML file named after the Pipeline name.
Here is an example for a Pipeline named Example-Pipeline, displayed in the UI:
It's YAML file is named Example-Pipeline.yaml:
harnessApiVersion: '1.0' # Harness API version.
type: PIPELINE # YAML file type.
description: This is an example pipeline for YAML. # Pipeline description.
pipelineStages: # Each pipeline stage is a separate type.
- type: ENV_STATE # First stage, Execution Step.
name: Basic-Build # Name given to stage.
parallel: false # Boolean for Executed in Parallel option.
workflowName: Basic-Example # Workflow executed in this stage.
- type: APPROVAL # Second stage, Approval Step.
name: Approval 1 # Name given to stage.
parallel: false
properties:
userGroups:
- DocExample # Name of User Group for approval.
timeoutMillis: 604800000 # How long to wait for approval before failing.
approvalStateType: USER_GROUP # Approval requires User Group.
- type: ENV_STATE # Third stage, Execution Step.
name: QA # Name given to stage.
parallel: false
workflowName: Canary-Example # Workflow executed in this stage.
Limitations
- If you rename a Pipeline in Git and sync that change with Harness, any Triggers using that Pipeline are deleted.
- If you rename a Workflow in Git and sync that change with Harness, Triggers are maintained because a duplicate that Pipeline are deleted.