CI environment variables reference
This topic describes environment variables you might encounter when using Harness CI. These variables contain information about the build, such as how the build started, codebase information, build infrastructure, step identifiers, and more. These are pipeline runtime environment variables, and they are available to all stages and steps in the pipeline.
This reference focuses on Harness CI-specific environment variables prefixed by CI_
, HARNESS_
, and DRONE_
. However, additional environment variables can be present based on your build infrastructure, build tools, specific steps used, and other pipeline configuration possibilities. You can use a printenv
command in a Run step to get a list of environment variables for a specific stage.
Reference environment variables
You can reference Harness CI environment variables through either:
- Direct reference in scripts and commands, when available, such as
machine ${DRONE_NETRC_MACHINE}
. - Equivalent Harness expressions, such as
<+pipeline.sequenceId>
forHARNESS_BUILD_ID
.
Variable resolution
The value of an environment variable depends on the build conditions. A variable is resolved only if the build includes the necessary information for that variable.
For example, DRONE_PULL_REQUEST
is only resolved if the build started from a pull request. Builds that aren't started from a PR won't have a PR number to assign to that variable.
Environment variable values in manual builds
Manual builds occur when you manually run a pipeline from within Harness. If your pipeline has a codebase configuration, you can select a branch, PR, or tag to build.
- Manual branch builds: Manually run a pipeline and select the Git Branch build type. Harness looks for the source code attached to the specified Branch Name, and it clones that specific source code for the build.
- Manual pull request (PR) builds: Manually run a pipeline and select the Git Pull Request build type. Harness looks for the source code attached to the specified Pull Request Number, and it clones that specific source code for the build.
- Manual tag builds: Manually run a pipeline and select the Git Tag build type. Harness looks for the source code attached to the specified Tag Name, and it clones that specific source code for the build.
Environment variable values in webhook trigger builds
You can automatically trigger pipelines using Git events. Webhook triggers listen for specific events in your code repo, and then trigger builds when those events occur.
- Pull request (PR) triggers: A Pull Request Webhook Event automatically starts a build in Harness when there is a new pull request event on the pipeline's associated Git repo. You can specify the type of pull request events to track, such as close, open, update/edit, reopen, and so on.
- Push triggers: A Push Webhook Event automatically starts a build in Harness when there is a new branch or tag push event on the pipeline's associated Git repo.
Difference between DRONE_ and PLUGIN_ variables
DRONE_
variables are environment variables that are automatically set at the pipeline level. These are pipeline runtime variables, and they are available to all stages and steps in the pipeline. Many DRONE_
variables have equivalent CI_
or HARNESS_
environment variables. The DRONE_
variables are derived from Drone, which is part of Harness CI. Providing first-class support for Drone environment variables makes it easier to migrate from standalone Drone to Harness CI and provides better support for Drone plugins that use those variables.
PLUGIN_
variables represent plugin settings. There are three ways they can be defined depending on their usage and the build infrastructure:
- The plugin step's settings. For example,
setting.url
becomesPLUGIN_URL
at runtime. - Stage variables. For example, you can use the
PLUGIN_DRY_RUN
stage variable to Build a Docker image without pushing. - Environment variables in Build and Push steps running on Kubernetes cluster build infrastructure.
Codebase and trigger variables
These variables contain codebase attributes and information about how builds start (triggers). For more information about codebase attributes and expressions you can use to reference codebase attributes, go to the CI codebase variables reference.
DRONE_BRANCH
For branch builds and PR builds, this variable's value is the target branch for the build.
For tag push webhook triggers, this variable's value is the tag reference, such as refs/tags/TAG_NAME
.
For manual tag builds, this variable is not applicable and can be empty.
Depending on the build type, this can be equivalent to the expressions <+codebase.targetBranch>
or <+codebase.branch>
.
This variable is similar to DRONE_COMMIT_BRANCH
and DRONE_TARGET_BRANCH
.
DRONE_BUILD_ACTION
Only applicable to PR webhook triggers, this variable describes the PR event that triggered the build, such as open
or reopen
.
For all other build types, this variable is not applicable.
This variable is similar, but not equivalent, to the expression <+trigger.event>
.
DRONE_BUILD_EVENT
The type of event that started the build, such as push
, pull_request
, or tag
.
This is similar to the expressions <+codebase.build.type>
and <+pipeline.triggerType>
.
DRONE_BUILD_TRIGGER
Source that started the build, a user or webhook. Similar, but not equivalent, to the expressions <pipeline.triggerType>
or <pipeline.triggeredBy.name>
. May be empty.
DRONE_CALVER
Only applicable to build started by tag push webhook triggers. If the Git tag is a valid calendar version string, this value represents the tag as a valid calver string, such as 19.1.0-beta.20190318
.
Harness CI doesn't support DRONE_CALVER
variations, such as DRONE_CALVER_SHORT
.
DRONE_COMMIT
The full Git commit SHA for the latest commit in the branch, tag, or PR. Corresponds with the expressions <+codebase.commitSha>
or <+trigger.commitSha>
.
It can be the same as DRONE_COMMIT_SHA
.
For Bitbucket PR builds (manual or webhook), this expression returns a shortened SHA due to the Bitbucket webhook payload only sending shortened SHAs.
This isn't the same as the short SHA returned by <+codebase.shortCommitSha>
.
DRONE_COMMIT_AFTER
This variable provides the Git commit SHA after applying a patch. It can be used in conjunction with DRONE_COMMIT_BEFORE
to create a diff.
Possible values include: a unique commit SHA, the same SHA as DRONE_COMMIT
, empty, or all zeros.
CI_COMMIT_AUTHOR/DRONE_COMMIT_AUTHOR
User name of the Git account associated with the build. Equivalent to the expressions <+codebase.gitUser>
and <+trigger.gitUser>
. Can sometimes be null
or masked in build logs.
CI_COMMIT_AUTHOR_AVATAR/DRONE_COMMIT_AUTHOR_AVATAR
User avatar of the Git account associated with the build. Equivalent to the expression <+codebase.gitUserAvatar>
. Can be empty.
CI_COMMIT_AUTHOR_EMAIL/DRONE_COMMIT_AUTHOR_EMAIL
User email of the Git account associated with the build. Equivalent to the expression <+codebase.gitUserEmail>
. Can be sometimes be empty/null
or masked in build logs.
CI_COMMIT_AUTHOR_NAME/DRONE_COMMIT_AUTHOR_NAME
User-defined display name for the Git user associated with the build. Can be empty.
DRONE_COMMIT_BEFORE
This variable provides the Git commit SHA before applying a patch. It can be used in conjunction with DRONE_COMMIT_AFTER
to create a diff.
Possible values include: a unique commit SHA, the same SHA as DRONE_COMMIT
, empty, or all zeros.
CI_COMMIT_BRANCH/DRONE_COMMIT_BRANCH
For branch builds and PR builds, this variable's value is the target branch for the build.
For tag push webhook triggers, this variable's value is the tag reference, such as refs/tags/TAG_NAME
.
For manual tag builds, this variable is not applicable and can be empty.
Depending on the build type, this can be equivalent to the expressions <+codebase.targetBranch>
or <+codebase.branch>
.
This variable is similar to DRONE_BRANCH
and DRONE_TARGET_BRANCH
.
DRONE_COMMIT_LINK
Provides a link to the commit, PR, or tag in SCM.
For PR builds, this is equivalent to the expression <+codebase.pullRequestLink>
.
CI_COMMIT_MESSAGE/DRONE_COMMIT_MESSAGE
The latest commit message from a tag, branch, or PR. Equivalent to the expression <+codebase.commitMessage>
.
When referenced in an echo
, this value can cause execution errors if the message has multiple lines. The shell might attempt to execute the commit message as a command. You might need to include additional handling if you want to echo multiline commit messages.
CI_COMMIT_REF/DRONE_COMMIT_REF
Provides a Git reference corresponding to the branch, tag, or PR. For example:
- Branch reference:
refs/heads/main
- Tag reference:
refs/tags/v1.0.0
- PR reference:
refs/pull/1/head
For manual builds, this can be empty.
This is similar to <+codebase.commitRef>
.
CI_COMMIT_SHA/DRONE_COMMIT_SHA
The full Git commit SHA for the latest commit in the branch, tag, or PR. Corresponds with the expressions <+codebase.commitSha>
or <+trigger.commitSha>
.
It can be the same as DRONE_COMMIT.
CI_REPO_REMOTE/DRONE_GIT_HTTP_URL
Provides the HTTP(S) URL to clone a pipeline's codebase, such as https://github.com/octocat/hello-world.git
.
DRONE_GIT_SSH_URL
Provides the SSH URL to clone a pipeline's codebase, such as ssh://git@github.com:octocat/hello-world.git
.
DRONE_PULL_REQUEST
For pull request builds, this variable provides the pull request number. For other builds, this variable is empty. This is equivalent to the expressions <+codebase.prNumber>
and <+trigger.prNumber>
.
DRONE_PULL_REQUEST_TITLE
For pull request builds, this variable provides the pull request title. For other builds, this variable is empty. This is equivalent to the expressions <+codebase.prTitle>
and <+trigger.prTitle>
.
CI_REMOTE_URL/DRONE_REMOTE_URL
Legacy variable provided for backward compatibility only. It is the same as DRONE_GIT_HTTP_URL
.