SCM status checks
Configure branch protection and status checks for codebases associated with Harness CI.
If your pipelines use webhook triggers, you can get Harness build statuses in your PRs. However, you must configure your protection rules in your SCM provider if you want failed/running builds to block PR merges.
Failed pipelines don't 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.
If you want 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, you can add custom SCM status checks to your CI pipelines.
SCM links in build details
When viewing builds in Harness, builds triggered by webhooks can include a link to the PR or commit that started the build.
Pipeline links in PRs
When viewing a PR in your SCM provider, if a manual or webhook build ran from that PR, then you can follow the Details link from the PR's Git status to the build details page in Harness. This is supported for both manual and webhook PR builds, but it is not supported for all SCM providers.
To get status updates in your PRs, you must:
Configure a default codebase for your pipeline. Your pipeline must have a Build stage. Build updates are only exported for Build stages.
Make sure you enable API access in your code repo connector settings.
Run PR builds. Branch and tag builds don't send PR status updates. You can use webhook triggers to automatically run builds when PRs are created or updated.
Custom SCM status checks
If you want to pull PR status check information into a Harness pipeline, you can use Run steps to query your SCM provider's API and include custom SCM status checks in your CI pipelines.
Add a custom status check
These steps explain how to add a status check that uses the GitHub API. For information about leveraging another SCM provider's API, refer to that provider's API documentation.
You need a CI pipeline with a Build stage where you'll add the Run step.
Create GitHub Personal Access Token to use for authentication, and save the token as a Harness text secret.
Add a Run step to your Build (
CI) stage.Enter a Name for the step.
If required by your build infrastructure, provide the Container Registry and Image. For more information on how to set this up, please look at the section below about 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:latestfor the official cURL Docker Hub image.To learn more about this setting and when it is required, look at the section below about Container Registry and Image
For Shell, select Sh.
In Command, enter a script that calls the GitHub API, for example:
The above example calls the GitHub API and uses the GitHub token secret for authentication. It uses expressions 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 the above script, replace
YOUR_GITHUB_ORGANIZATIONwith your GitHub organization name, and replaceYOUR_GITHUB_TOKEN_SECRET_IDwith the ID of the Harness text secret that contains your GitHub personal access token.Configure additional settings as necessary for your script and build infrastructure. For example, you might want to set container resource limits, export output variables, or inject environment variables. For more information about Run step settings, go to Use Run steps.
The above 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:
Create reusable status check steps
If you want to include status checks in multiple pipelines, you might want to create reusable templates or plugins.
Step templates help you quickly reuse customized or complex steps in multiple pipelines. For example, here is a YAML example of a step template for a GitHub status check step:
You can package your status check script in a custom plugin and then add it to your pipelines in a Plugin step.
Container Registry and Image
The build environment must have the necessary binaries for the SCM Status Checks. Depending on the stage's build infrastructure, SCM Status Checks steps can use binaries that exist in the build environment, or use Container Registry and Image to pull an image, such as a public or private Docker image, that contains the required binaries.
Troubleshoot status checks
Go to the Harness CI Knowledge Base for common questions and issues related to codebases and SCM status checks, such as:
For troubleshooting information for Git event (webhook) triggers, go to Troubleshoot Git event triggers.
Last updated
Was this helpful?