> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/built-in-cie-codebase-variables-reference.md).

# CI codebase variables reference

Use Harness built-in expressions to reference Git codebase attributes in pipeline stages.

In Harness CI, you set up a [codebase](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md) by creating a [Harness connector](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/git-clone-step.md#connector) that connects to a Git repo. Pipelines use this connector to clone the code that you want to build and test. When a pipeline runs, Harness also fetches Git details and displays them in the [build details](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/viewing-builds.md).

## What you will learn in this topic

In this topic, you learn:

* How Harness resolves codebase [environment variables](https://developer.harness.io/continuous-integration/troubleshooting-and-resources/troubleshoot-harness-ci/ci-env-var.md) for manual builds, webhook triggers, and other scenarios.
* Which [Harness expressions](https://developer.harness.io/harness-platform/use-harness-platform/variables-and-expressions/harness-variables.md) you can use to reference Git codebase attributes in your pipelines.

## Before you begin

Before you start, make sure you have a [CI pipeline](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/prep-ci-pipeline-components.md) with a [codebase](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md) configured.

## Variable resolution

The values of codebase variables depend on:

* The pipeline's [codebase](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md) configuration. For full support, use a supported provider: GitHub, Bitbucket, or GitLab. With other providers, Harness might not resolve some variables.
* The pipeline's [code repo connector](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/git-clone-step.md#connector). It must use **Username and Token** authentication and allow API access (**Enable API access**).
* How the build started, whether manually or by a webhook trigger.

Harness resolves a variable only if the build includes the information that the variable needs. For example, Harness resolves `<+codebase.prNumber>` only if the build started from a pull request. Builds that do not start from a PR have no PR number to assign to that variable.

{% hint style="info" %}
Codebase variables are local to the **Build** (`CI`) stage where Harness resolved them. For example, if your pipeline has a **Build** stage and a **Deploy** stage, the codebase variables are accessible in the **Build** stage only.
{% endhint %}

### Manual builds

Manual builds occur when you manually run a pipeline from within Harness. You can specify 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 clones that 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 clones that 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 clones that source code for the build.

{% hint style="info" %}
`trigger.*` expressions are always `null` for manual builds. Trigger expressions get values from automated triggers, such as webhook triggers. Manual builds do not use an automated trigger, so no values are available for these expressions.

If you build both manually and through triggers, use expressions that resolve for both build types, such as `<+codebase.prNumber>` instead of `<+trigger.prNumber>`.
{% endhint %}

### Webhook triggers

You can automatically [trigger pipelines using Git events](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggering-pipelines.md). [Webhook triggers](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggers-reference.md) listen for specific events in your code repo and trigger builds when those events occur.

Harness maps values in the webhook payload to the build's codebase variables. The variables that Harness resolves depend on the event type and the payload contents.

* **Pull request (PR) triggers:** A **Pull Request Webhook Event** automatically starts a build in Harness when a new pull request event occurs on the pipeline's associated Git repo. You can specify the type of [pull request events](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggers-reference.md#event-and-actions) to track, such as close, open, update/edit, and reopen.
* **Push triggers:** A **Push Webhook Event** automatically starts a build in Harness when a new branch or tag push event occurs on the pipeline's associated Git repo.

### Unresolved variables

Harness does not resolve some codebase variables in these scenarios:

* **Cron triggers:** Builds that cron triggers start do not contain specific Git event information. They do not provide a payload that Harness can use to resolve codebase variables the way it does for PR and push triggers.
* **Non-default codebases:** Harness resolves codebase variables only for the pipeline's [default codebase](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md). If you [disable clone codebase](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md#disable-clone-codebase-for-specific-stages) or a stage [clones additional codebases](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/clone-and-process-multiple-codebases-in-the-same-pipeline.md) through **Run** or **Git Clone** steps, Harness does not produce codebase variables for these non-default codebases.
* **Git provider:** Harness does not support all Git providers. Some providers do not supply relevant values for all expressions.

## Reference codebase variables

Use [Harness expressions](https://developer.harness.io/harness-platform/use-harness-platform/variables-and-expressions/runtime-inputs.md#expressions) to reference codebase attributes in your **Build** (`CI`) stages. Expressions use the format `<+PARENT.CHILD>`, such as `<+codebase.commitSha>`, where `commitSha` is an attribute within `codebase`.

For example, add a [Run step](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) with a series of `echo` commands to your pipeline to reference codebase variables:

{% tabs %}
{% tab title="Visual" %}
![A Run step with echo commands and the corresponding build logs.](https://4226796345-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqKtVmwAGTfGQS1MVC97G%2Fuploads%2Fgit-blob-49a169277000451613063800e72de740046c5231%2Fbuilt-in-cie-codebase-variables-reference-512.png?alt=media)
{% endtab %}

{% tab title="YAML" %}

```yaml
              - step:
                  type: Run
                  name: echo codebase
                  identifier: echo_codebase
                  spec:
                    shell: Sh
                    command: |-
                      echo <+codebase.repoUrl>
                      echo <+codebase.prNumber>
                      echo <+codebase.prTitle>
                      echo <+codebase.pullRequestLink>
                      echo <+codebase.targetBranch>
                      echo <+codebase.sourceBranch>
                      echo <+codebase.commitSha>
                      echo <+codebase.gitUserId>
                      echo <+codebase.gitUserEmail>
                      echo <+codebase.state>
```

In the [build logs](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/viewing-builds.md), you can see the value of each variable:

```
+ echo https://github.com/**************/CI-How-Tos
+ echo 8
+ echo Update README.md
+ echo https://github.com/**************/CI-How-Tos/pull/8
+ echo main
+ echo **************-patch-5-1
+ echo 85116fa2f04858cd5e946d69f24d7359205a0737
+ echo **************
+ echo
+ echo open
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can use expressions to reference the value of some `DRONE_` environment variables. Go to [CI environment variables reference](https://developer.harness.io/continuous-integration/troubleshooting-and-resources/troubleshoot-harness-ci/ci-env-var.md) for more information.
{% endhint %}

### Build start variables

These variables describe how the build started.

| Variable                 | Value                                                                                                                                                                                               | Expression               | Exclusions                       |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -------------------------------- |
| `<+codebase.build.type>` | The event type that started the build: `tag` for a manual tag build, `branch` for a manual branch build, `PR` for a manual or webhook PR build, or `Push` for a branch or tag push webhook trigger. | `<+codebase.build.type>` | None                             |
| `<+trigger.type>`        | The trigger type. For PR and push webhook triggers, the value is `Webhook`.                                                                                                                         | `<+trigger.type>`        | Not available for manual builds. |
| `<+trigger.event>`       | The webhook trigger event category: `PR` or `PUSH`.                                                                                                                                                 | `<+trigger.event>`       | Not available for manual builds. |

Use `<+codebase.build.type>` to create conditions based on the build type. For example, use `<+codebase.build.type>=="TYPE"`, where `TYPE` is `tag`, `PR`, `branch`, or `Push`.

### Branch, PR, & tag variables

These variables provide information about the branch, PR, or tag associated with the build.

| Variable                      | Value                                                                                                                                                                                                              | Expression                                                                                                               | Exclusions                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<+codebase.branch>`          | The PR target branch or branch specified for a branch build. `<+codebase.branch>` always resolves to the target branch. For PR builds and triggers, use `<+codebase.sourceBranch>` and `<+codebase.targetBranch>`. | `<+codebase.branch>`                                                                                                     | For tag builds, the value is `null` or a tag path, such as `refs/tags/TAG_NAME`. Use `<+codebase.tag>`.                                                                                                                                                                                                                                                                                                                                                                         |
| `<+codebase.prNumber>`        | The Git PR number.                                                                                                                                                                                                 | Manual PR builds: `<+codebase.prNumber>`. PR webhook triggers: `<+codebase.prNumber>` or `<+trigger.prNumber>`.          | `null` for tag and branch builds.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `<+codebase.prTitle>`         | The Git PR title.                                                                                                                                                                                                  | Manual PR builds: `<+codebase.prTitle>`. PR webhook triggers: `<+codebase.prTitle>` or `<+trigger.prTitle>`.             | `null` for tag and branch builds.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `<+codebase.pullRequestBody>` | The Git PR description.                                                                                                                                                                                            | `<+codebase.pullRequestBody>`                                                                                            | `null` for tag and branch builds.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `<+codebase.pullRequestLink>` | The PR link.                                                                                                                                                                                                       | `<+codebase.pullRequestLink>`                                                                                            | `null` for tag and branch builds.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `<+codebase.sourceBranch>`    | The source branch for a PR.                                                                                                                                                                                        | Manual PR builds: `<+codebase.sourceBranch>`. Webhook triggers: `<+codebase.sourceBranch>` or `<+trigger.sourceBranch>`. | Tag builds: Always `null`. Use `<+codebase.tag>`. Branch builds: Always `null`. Use `<+codebase.branch>`. Reruns of webhook trigger or manual PR builds: Resolves to `null` when you manually rerun the build. Instead of using **Re-run** on the [Build details page](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/viewing-builds.md), start a new build. For example, push a change to trigger the webhook or run a new manual PR build. |
| `<+codebase.tag>`             | The Git tag specified for a tag build.                                                                                                                                                                             | `<+codebase.tag>`                                                                                                        | `null` for PR and branch builds.                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `<+codebase.targetBranch>`    | The target branch for a PR.                                                                                                                                                                                        | Manual PR builds: `<+codebase.targetBranch>`. Webhook triggers: `<+codebase.targetBranch>` or `<+trigger.targetBranch>`. | Tag builds: Always `null`. Use `<+codebase.tag>`. Branch builds: Always `null`. Use `<+codebase.branch>`. Reruns of webhook trigger or manual PR builds: Resolves to `null` when you manually rerun the build. Start a new build instead. For example, push a change to trigger the webhook or run a new manual PR build.                                                                                                                                                       |

### Commit variables

These variables provide information about some commits associated with the build.

| Variable                    | Value                                                                    | Expression                                                                                                                     | Exclusions                        |
| --------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------- |
| `<+codebase.baseCommitSha>` | The Git commit SHA of a PR's base commit.                                | Manual PR builds: `<+codebase.baseCommitSha>`. PR webhook triggers: `<+codebase.baseCommitSha>` or `<+trigger.baseCommitSha>`. | `null` for tag and branch builds. |
| `<+codebase.commitMessage>` | The latest commit message in the branch, tag, or PR.                     | `<+codebase.commitMessage>`                                                                                                    | None                              |
| `<+codebase.commitRef>`     | A Git commit reference.                                                  | `<+codebase.commitRef>`                                                                                                        | None                              |
| `<+codebase.commitSha>`     | The full Git commit SHA for the latest commit in the branch, tag, or PR. | Manual builds: `<+codebase.commitSha>`. Webhook triggers: `<+codebase.commitSha>` or `<+trigger.commitSha>`.                   | None                              |

{% hint style="info" %}
For Bitbucket PR builds (manual or webhook), this expression returns a *shortened* SHA because the Bitbucket webhook payload sends only shortened SHAs.

This shortened SHA *isn't* the same as the short SHA that [`<+codebase.shortCommitSha>`](#codebaseshortcommitsha) returns.
{% endhint %}

| Variable                     | Value                                                       | Expression                   | Exclusions                                   |
| ---------------------------- | ----------------------------------------------------------- | ---------------------------- | -------------------------------------------- |
| `<+codebase.mergeSha>`       | The SHA of the merge commit when a Bitbucket PR merges.     | `<+codebase.mergeSha>`       | Applies only to merged PRs in Bitbucket SCM. |
| `<+codebase.shortCommitSha>` | The short SHA, seven characters, of the build's commit SHA. | `<+codebase.shortCommitSha>` | None                                         |

### Git user variables

These variables provide information about the Git user account associated with the build.

| Variable                    | Value                                                                                                 | Expression                                                                                             | Exclusions |
| --------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------- |
| `<+codebase.gitUser>`       | The user name of the Git account associated with the build. It can be `null` or masked in build logs. | Manual builds: `<+codebase.gitUser>`. Webhook triggers: `<+codebase.gitUser>` or `<+trigger.gitUser>`. | None       |
| `<+codebase.gitUserAvatar>` | The link to the avatar of the Git account associated with the build.                                  | `<+codebase.gitUserAvatar>`                                                                            | None       |
| `<+codebase.gitUserEmail>`  | The email of the Git account associated with the build. It can be `null` or masked in build logs.     | `<+codebase.gitUserEmail>`                                                                             | None       |
| `<+codebase.gitUserId>`     | The ID of the Git account associated with the build. It can be `null` or masked in build logs.        | `<+codebase.gitUserId>`                                                                                | None       |

### Repo variables

These variables provide information about the Git repo associated with the build.

| Variable                | Value                                                                 | Expression                                                                                             | Exclusions                        |
| ----------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | --------------------------------- |
| `<+codebase.repoUrl>`   | The Git repo link associated with the build.                          | Manual builds: `<+codebase.repoUrl>`. Webhook triggers: `<+codebase.repoUrl>` or `<+trigger.repoUrl>`. | None                              |
| `<+codebase.state>`     | The state of the Git working directory associated with a PR.          | `<+codebase.state>`                                                                                    | `null` for tag and branch builds. |
| `<+trigger.sourceRepo>` | The PR, branch, or tag source repo, if applicable. Otherwise, `null`. | `<+trigger.sourceRepo>`                                                                                | Not available for manual builds.  |

## Next steps

* [Configure codebase](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md): Configure the default codebase that your pipeline clones.
* [Git Clone step in CI](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/git-clone-step.md): Use `<+codebase.branch>` and `<+codebase.tag>` to match a cloned repo to your pipeline's codebase.
* [SCM status checks](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/scm-status-checks.md): Use `<+codebase.commitSha>` in custom status check scripts.

{% @harness-feedback/feedback %}
