> 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/scm-status-checks.md).

# SCM status checks

Configure branch protection and status checks for codebases associated with Harness CI.

If your pipelines use [webhook triggers](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggering-pipelines.md), you can get [Harness build statuses in your PRs](#pipeline-links-in-prs). To make failed or running builds block PR merges, configure your protection rules *in your SCM provider*.

{% hint style="warning" %}
Failed pipelines do not inherently block PR merges. Harness can send pipeline statuses to your PRs, but you must configure branch protections and checks, such as protection rules, CODEOWNERS, linting, and other checks or restrictions, in your source control provider.
{% endhint %}

To pull PR status check information into a Harness pipeline, such as to determine whether to run a specific step based on the outcome of a check, [add custom SCM status checks to your CI pipelines](#custom-scm-status-checks).

## What you will learn in this topic

By the end of this topic, you learn how to:

* Find SCM links in build details and pipeline links in PRs.
* Get Harness build statuses in your PRs.
* Add custom SCM status checks to your CI pipelines.
* Create reusable status check steps.
* Configure the **Container Registry** and **Image** settings for status check steps.

## Before you begin

Before you configure branch protection and status checks, make sure you have the following:

* A [CI pipeline](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/prep-ci-pipeline-components.md) with a [Build stage](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/ci-stage-settings.md).
* A [default 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) configured for your pipeline.
* [Webhook triggers](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggering-pipelines.md) if you want builds to run automatically when PRs are created or updated.

## SCM links in build details

When you [view builds](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/viewing-builds.md) in Harness, builds that webhooks trigger can include a link to the PR or commit that started the build.

![A build on the Builds list that was triggered by a commit. There is a link to the triggering commit.](https://4226796345-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqKtVmwAGTfGQS1MVC97G%2Fuploads%2Fgit-blob-2c02afe67c56237e81a32a1d3b59ec2a4248fc02%2Fci-builds-list-sc-link.png?alt=media)

## Pipeline links in PRs

When you view a PR in your SCM provider, if a manual or webhook build ran from that PR, you can follow the **Details** link from the PR's Git status to the build details page in Harness. Harness supports this link for both manual and webhook PR builds, but not for all SCM providers.

![A PR's Git status with a link to a Harness CI build.](https://4226796345-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqKtVmwAGTfGQS1MVC97G%2Fuploads%2Fgit-blob-dbb38235b89b0a45de315b98c2d2f2c791dfb037%2Fci-builds-gh-pr-link.png?alt=media)

To get status updates in your PRs:

1. [Configure a default codebase for your pipeline.](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md#configure-the-default-codebase) Your pipeline must have a Build stage. Harness exports build updates only for Build stages.
2. Enable API access in your [code repo connector](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/git-clone-step.md#connector) settings.

![](https://4226796345-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqKtVmwAGTfGQS1MVC97G%2Fuploads%2Fgit-blob-a94a2fd2dfbd4b4cec4e0d13a1f63dcc35bd302e%2Fscmstatus-apiauth.png?alt=media)

3. Run PR builds. Branch and tag builds do not send PR status updates. You can use [webhook triggers](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggering-pipelines.md) to run builds automatically when PRs are created or updated.

{% hint style="info" %}
**Custom status check names**

To customize the status check names that appear on your PRs, configure the **Send status to Git** option in your pipeline stages. This option lets you use business-friendly names, such as `Quality Gate` or `Security Scan`, instead of technical stage names. Go to [Send Stage Execution Status to Git on Pull Requests](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggering-pipelines.md#send-stage-execution-status-to-git-on-pull-requests) for details.
{% endhint %}

## Custom SCM status checks

To pull PR status check information into a Harness pipeline, use [Run steps](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) to query your SCM provider's API and include custom SCM status checks in your CI pipelines.

### Add a custom status check

These steps add a status check that uses the GitHub API. Go to that provider's API documentation for information about using another SCM provider's API.

1. Create a [GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) to use for authentication, and save the token as a [Harness text secret](https://developer.harness.io/harness-platform/use-harness-platform/secrets/add-use-text-secrets.md).
2. In your [CI pipeline](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/prep-ci-pipeline-components.md), add a [Run step](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) to your **Build** (`CI`) stage.
3. Enter a **Name** for the step.
4. If your build infrastructure requires it, provide the **Container Registry** and **Image**:
   * **Container Registry** is a container registry connector, such as a Docker connector.
   * **Image** is the FQN or artifact name and tag of a Docker image that has cURL installed, such as `curlimages/curl:latest` for the [official cURL Docker Hub image](https://hub.docker.com/r/curlimages/curl).
   * Go to [Container Registry and Image](#container-registry-and-image) for these settings and when they are required.
5. For **Shell**, select **Sh**.
6. In **Command**, enter a script that calls the GitHub API, for example:

   ```shell
   curl -i -X POST \
     -H "Authorization: Bearer <+secrets.getValue('account.YOUR_GITHUB_TOKEN_SECRET_ID')>" \
     -H "Accept: application/vnd.github.v3+json" \
     https://api.github.com/repos/YOUR_GITHUB_ORGANIZATION/<+pipeline.properties.ci.codebase.repoName>/statuses/<+codebase.commitSha> \
     -d '{"state":"pending","target_url":"<+pipeline.execution.url>","description":"Test is running","context":"harness-ci/tests"}'
   ```

   This example calls the GitHub API and uses the GitHub token secret for authentication. It uses [expressions](https://developer.harness.io/harness-platform/use-harness-platform/variables-and-expressions/harness-variables.md) to pull information from the pipeline, such as the target repository name (`<+pipeline.properties.ci.codebase.repoName>`) and the pipeline build link (`<+pipeline.execution.url>`).

   If you use this script, replace `YOUR_GITHUB_ORGANIZATION` with your GitHub organization name, and replace `YOUR_GITHUB_TOKEN_SECRET_ID` with the ID of the Harness text secret that contains your GitHub personal access token.
7. Configure additional settings as necessary for your script and build infrastructure. For example, you can set container resource limits, export output variables, or inject environment variables. Go to [Use Run steps](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) for **Run** step settings.

This script is a basic GitHub status check. You can modify the script to include more commands, get other information from the payload, or call a different SCM provider's API. For example, the following script takes different actions depending on the resulting status, and it includes environment variables and [conditional execution settings](https://developer.harness.io/harness-platform/use-harness-platform/pipelines/step-skip-condition-settings.md):

```shell
# status="<+execution.steps.STEP_ID.status>"
# name="harness-ci/tests"

echo "Send Commit Status"

if [[ "$status" == "SUCCEEDED" ]]; then
  state="success"
  description="$name scan passed for <+pipeline.properties.ci.codebase.repoName>"
elif [[ "$status" == "PENDING" ]]; then
  state="pending"
  description="$name scan pending for <+pipeline.properties.ci.codebase.repoName>"
else
  state="failure"
  description="$name scan failed for <+pipeline.properties.ci.codebase.repoName>"
fi

curl -i -u YOUR_GITHUB_ORGANIZATION:<+secrets.getValue("account.YOUR_GITHUB_TOKEN_SECRET_ID")> \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/YOUR_GITHUB_ORGANIZATION/<+pipeline.properties.ci.codebase.repoName>/statuses/<+codebase.commitSha> \
  -d "{\"state\":\"$state\",\"target_url\":\"<+pipeline.execution.url>\",\"description\":\"$description\",\"context\":\"$name\"}"
```

### Create reusable status check steps

To include status checks in multiple pipelines, create reusable templates or plugins.

{% tabs %}
{% tab title="Create a step template" %}
[Step templates](https://developer.harness.io/harness-platform/use-harness-platform/templates/run-step-template-quickstart.md) help you quickly reuse customized or complex steps in multiple pipelines. For example, the following YAML is a step template for a GitHub status check step:

{% code expandable="true" %}

```yaml
template:
  name: Send GitHub Status
  type: Step
  projectIdentifier: YOUR_HARNESS_PROJECT_ID
  orgIdentifier: YOUR_HARNESS_ORGANIZATION_ID
  spec:
    type: Run
    spec:
      connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
      image: curlimages/curl:7.82.0
      shell: Sh
      command: |+
        # status="<+execution.steps.STEP_ID.status>"
        # name="harness-ci/tests"

        echo "Send Commit Status"

        if [[ "$status" == "SUCCEEDED" ]]; then
          state="success"
          description="$name scan passed for <+pipeline.properties.ci.codebase.repoName>"
        elif [[ "$status" == "PENDING" ]]; then
          state="pending"
          description="$name scan pending for <+pipeline.properties.ci.codebase.repoName>"
        else
          state="failure"
          description="$name scan failed for <+pipeline.properties.ci.codebase.repoName>"
        fi

        curl -i -u YOUR_GITHUB_ORGANIZATION:<+secrets.getValue("account.YOUR_GITHUB_TOKEN_SECRET_ID")> \
          -X POST \
          -H "Accept: application/vnd.github.v3+json" \
          https://api.github.com/repos/YOUR_GITHUB_ORGANIZATION/<+pipeline.properties.ci.codebase.repoName>/statuses/<+codebase.commitSha> \
          -d "{\"state\":\"$state\",\"target_url\":\"<+pipeline.execution.url>\",\"description\":\"$description\",\"context\":\"$name\"}"

      envVariables:
        status: <+input>
        name: <+input>
      imagePullPolicy: IfNotPresent
    when:
      stageStatus: Success
      condition: <+codebase.build.type>=="PR"
  identifier: Send_Git_Status
  versionLabel: 1.0.0
```

{% endcode %}
{% endtab %}

{% tab title="Write a custom plugin" %}
You can package your status check script in a [custom plugin](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/use-drone-plugins/custom_plugins.md) and then add it to your pipelines in a [Plugin step](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/use-drone-plugins/custom_plugins.md#add-the-plugin-step).
{% endtab %}
{% endtabs %}

### Container registry and image

The build environment must have the binaries that the status check step needs. Depending on the stage's build infrastructure, the step can use binaries that exist in the build environment, or it can use **Container Registry** and **Image** to pull an image, such as a public or private Docker image, that contains the required binaries.

The stage's build infrastructure determines whether these fields are required or optional:

* [Kubernetes cluster build infrastructure](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/k8s-build-infrastructure/set-up-a-kubernetes-cluster-build-infrastructure.md): **Container Registry** and **Image** are always required.
* [Local runner build infrastructure](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/define-a-docker-build-infrastructure.md): Steps can use binaries available on the host machine. **Container Registry** and **Image** are required if the machine does not have the binaries you need.
* [Self-managed AWS/GCP/Azure VM build infrastructure](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/vm-build-infrastructure.md): Steps can use binaries that you make available on your build VMs. **Container Registry** and **Image** are required if the VM does not have the necessary binaries. These fields are under **Additional Configuration** for stages that use self-managed VM build infrastructure.
* [Harness Cloud build infrastructure](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/use-harness-cloud-build-infrastructure.md): Steps can use binaries available on Harness Cloud machines, as described in the [image specifications](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/use-harness-cloud-build-infrastructure.md#platforms-and-image-specifications). **Container Registry** and **Image** are required if the machine does not have the binaries you need. These fields are under **Additional Configuration** for stages that use Harness Cloud build infrastructure.

#### Expected values for Container Registry and Image

For **Container Registry**, provide a Harness container registry connector, such as a [Docker connector](https://developer.harness.io/harness-platform/use-harness-platform/connectors/artifact-repositories/add-a-docker-registry-connector/docker-registry-connector-settings-reference.md), that connects to a container registry, such as Docker Hub, where the **Image** is located.

For **Image**, provide the FQN (fully qualified name) or artifact name and tag of the Docker image to use when this step runs commands, for example `us-docker.pkg.dev/gar-prod-setup/harness-public/harness/cache:latest` or `maven:3.8-jdk-11`. If you do not include a tag, Harness uses the `latest` tag. Depending on the connector and feature flags, an FQN might be required.

You can use any Docker image from any Docker registry, including Docker images from private registries. Different container registries require different name formats, for example:

* **Docker Registry:** Enter the name of the artifact you want to deploy, such as `library/tomcat`. Wildcards are not supported. Images in private container registries require an FQN.
* **ECR:** Enter the FQN of the artifact you want to deploy. Images in repos must reference a path, for example: `40000005317.dkr.ecr.us-east-1.amazonaws.com/todolist:0.2`.
* **GAR:** Enter the FQN of the artifact you want to deploy. Images in repos must reference a path that starts with the project ID that the artifact is in, for example: `us-docker.pkg.dev/gar-prod-setup/harness-public/harness/cache:latest`.

  ![Configuring a Container Registry and Image settings.](https://4226796345-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqKtVmwAGTfGQS1MVC97G%2Fuploads%2Fgit-blob-d85318ad66a11eb441aa3298dd35b0263632e296%2Frun-step-settings-03.png?alt=media)

{% hint style="info" %}
**Remove the FQN requirement**

To use non-FQN references for non-public Docker registry connectors, contact Harness Support to add the feature flags `CI_REMOVE_FQN_DEPENDENCY_FOR_PRIVATE_REGISTRY_CONNECTOR_DOCKER` and `CI_REMOVE_FQN_DEPENDENCY`.
{% endhint %}

#### Pull images from JFrog Artifactory Docker registries

To pull images from a JFrog Artifactory Docker registry, create a Docker connector that connects to your JFrog instance. Do not use the Harness Artifactory connector, because the Artifactory connector supports only JFrog non-Docker registries.

To create a Docker connector for a JFrog Docker registry:

1. Go to **Connectors** in your Harness project, organization, or account resources, and select **New Connector**.
2. Under **Artifact Repositories**, select **Docker Registry**.
3. Enter a **Name** for the connector. The **Description** and **Tags** are optional.
4. For **Provider Type**, select **Other**.
5. In **Docker Registry URL**, enter your JFrog URL, such as `https://mycompany.jfrog.io`.
6. In the **Authentication** settings, use **Username and Password** authentication:
   * **Username:** Enter your JFrog username.
   * **Password:** Select or create a [Harness text secret](https://developer.harness.io/harness-platform/use-harness-platform/secrets/add-use-text-secrets.md) that contains the password for the **Username**.
7. Complete any other settings and save the connector. Go to the [Docker connector settings reference](https://developer.harness.io/harness-platform/use-harness-platform/connectors/artifact-repositories/add-a-docker-registry-connector/docker-registry-connector-settings-reference.md) for all Docker Registry connector settings.

After you create the connector, use the FQN location of the image unless you set the [feature flags listed in the previous section](#what-are-the-expected-values-for-container-registry-and-image).

{% hint style="info" %}
**JFrog URLs**

The JFrog URL format depends on your Artifactory configuration and on whether your Artifactory instance is local, virtual, remote, or behind a proxy. To get your JFrog URL, select your repo in your JFrog instance, select **Set Me Up**, and get the repository URL from the server name in the `docker-login` command. ![](https://4226796345-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqKtVmwAGTfGQS1MVC97G%2Fuploads%2Fgit-blob-40ea99861b466b0e5c5011164f9c9d2922586a63%2Fartifactory-connector-settings-reference-09.png?alt=media)

Go to the JFrog documentation on [Repository Management](https://www.jfrog.com/confluence/display/JFROG/Repository+Management) and [Configuring Docker Repositories](https://www.jfrog.com/confluence/display/RTF/Docker+Registry#DockerRegistry-ConfiguringDockerRepositories) for details.
{% endhint %}

## Troubleshooting

Go to [Troubleshoot Git event triggers](https://developer.harness.io/harness-platform/use-harness-platform/triggers/triggering-pipelines.md#troubleshoot-git-event-triggers) for troubleshooting information on Git event (webhook) triggers.

<details>

<summary>Failed pipelines do not block PR merges</summary>

Harness sends pipeline statuses to your pull requests (PRs). Configure branch protection rules, such as required status checks, in your source control management (SCM) provider to block merges when a pipeline fails.

</details>

<details>

<summary>Pipeline status updates are not sent to PRs</summary>

Harness uses the pipeline's default codebase connector to send status updates. Confirm that the pipeline has a default codebase with the correct code repository connector.

Run a PR build to send a status update. Branch and tag builds do not send PR status updates.

</details>

<details>

<summary>Build statuses do not appear on PRs, despite repository permissions</summary>

Confirm that the account used to create the connector token has repository write permissions. The token must also have the scopes required by your SCM provider.

For GitHub, personal access tokens require the `repo`, `user`, and `admin:repo_hook` scopes. The account that creates the token must have administrator permissions for the repository.

</details>

<details>

<summary>Why does a GitHub PR status check open another PR's build?</summary>

This issue occurs when two PRs use the same commit ID. Harness CI associates builds with commits, not individual PRs. The most recent build replaces the earlier build status.

Push a new commit to the affected PR, then run the pipeline again. The unique commit associates the status check with the correct build.

</details>

## 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.
* [CI codebase variables reference](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/built-in-cie-codebase-variables-reference.md): Reference Git codebase attributes, such as `<+codebase.commitSha>`, with built-in expressions.
* [Use Run steps](https://developer.harness.io/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md): Configure **Run** step settings for custom status checks.

{% @harness-feedback/feedback %}
