How do I report build statuses/checks to a self‑hosted GitHub Enterprise from Codemagic?
Last updated: June 26, 2026
Context
You can connect repositories hosted on a self‑hosted GitHub Enterprise (GHE) instance to Codemagic via SSH or HTTPS for builds. However, Codemagic’s GitHub App integration (which automatically posts Checks/Statuses to pull requests) only works with github.com and GHE Cloud. For self‑hosted GHE, posting build statuses or checks back to pull requests is not available natively and must be done via the GitHub API from your workflow.
Answer
Use a post-publish (or post-build) script in your codemagic.yaml to call the GitHub REST API and create/update commit statuses or check runs. Below is a minimal, reliable approach.
Connect your self‑hosted GHE repo to Codemagic
In Codemagic: Apps → Add app → Connect repository → Others.
Use SSH (recommended) or HTTPS:
SSH: git@your-ghe.example.com:org/repo.git
HTTPS: https://your-ghe.example.com/org/repo.git
If using SSH, add Codemagic’s public key as a Deploy Key in your GHE repo.
Create an access token for GHE
Use a Personal Access Token or GitHub App token with the necessary scopes:
For commit Statuses API: repo:status (and repo if private)
For Checks API: checks:write and repo
Store the token in Codemagic as an environment variable (e.g., GITHUB_TOKEN) with Secure set to On.
Allow network access (if applicable)
If your GHE instance is behind a firewall, allowlist Codemagic outbound IPs so webhooks and status updates work: https://docs.codemagic.io/getting-started/adding-apps/
Post a commit status (simple “status checks” shown in PRs)
scripts: - name: Report build status to GHE (Statuses API) script: | set -e GHE_URL="https://your-ghe.example.com" OWNER="your-org" REPO="your-repo" SHA=$(git rev-parse HEAD) CONTEXT="Codemagic CI/CD" TARGET_URL="$CM_BUILD_URL" # or another URL for logs/artifacts STATE="success" # one of: error, failure, pending, success DESCRIPTION="Build passed on Codemagic" curl -sS -X POST \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ "$GHE_URL/api/v3/repos/$OWNER/$REPO/statuses/$SHA" \ -d "{\"state\":\"$STATE\",\"target_url\":\"$TARGET_URL\",\"description\":\"$DESCRIPTION\",\"context\":\"$CONTEXT\"}"Add this under a post-publish or post-build phase in your codemagic.yaml and set STATE/description dynamically based on the build result.
Post a Check Run (richer UI with summaries and annotations)
scripts: - name: Report build result to GHE (Checks API) script: | set -e GHE_URL="https://your-ghe.example.com" OWNER="your-org" REPO="your-repo" SHA=$(git rev-parse HEAD) NAME="Codemagic Build" DETAILS_URL="$CM_BUILD_URL" TITLE="Codemagic build completed" SUMMARY="The build finished successfully." TEXT="See Codemagic for logs and artifacts." CONCLUSION="success" # one of: action_required, cancelled, failure, neutral, success, skipped, stale, timed_out curl -sS -X POST \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ "$GHE_URL/api/v3/repos/$OWNER/$REPO/check-runs" \ -d "{ \"name\": \"$NAME\", \"head_sha\": \"$SHA\", \"status\": \"completed\", \"conclusion\": \"$CONCLUSION\", \"details_url\": \"$DETAILS_URL\", \"output\": { \"title\": \"$TITLE\", \"summary\": \"$SUMMARY\", \"text\": \"$TEXT\" } }"Note: The Checks API requires GitHub Apps or tokens with checks:write on GHE versions that support Checks.
Make the script conditional on build result
Set STATE/CONCLUSION based on your pipeline outcome (e.g., pending at start, success/failure at end). You can run a small pre-build script to set “pending”, then finalize in post-publish.
Sources:
Codemagic post-publish scripts: https://docs.codemagic.io/yaml-publishing/post-publish/
GitHub REST API – Statuses: https://docs.github.com/en/rest/commits/statuses
GitHub REST API – Checks: https://docs.github.com/en/rest/checks
Connecting non-GitHub.com repos and IPs: https://docs.codemagic.io/getting-started/adding-apps/