Sub topic 18
Troubleshooting failed pipeline runs
This chapter assumes you can read a GitHub Actions workflow file and have run sf project deploy start and sf apex run test locally. It also assumes you have built the pull request validation and deploy-on-merge workflows from earlier chapters. Here you will learn to find the failing step, name the failure category, and fix it without guessing.
Start with the failing step
Open the failed run in the Actions tab. GitHub marks the first step that returned a non-zero exit code with a red cross, and later steps are skipped. Expand that step and read from the bottom up. The last lines usually hold the error message, and the lines above them hold the context.
Ask three questions in order:
- Which step failed: installing the CLI, authenticating, deploying, or testing?
- Does the same command fail on your machine against the same org?
- What changed since the last green run: the code, the org, the CLI version, or a secret?
The diagram shows how these questions sort most failures into a few categories.
Authentication failures
The login step fails before anything touches the org. Common causes:
- Empty secret. Secrets are not passed to workflows triggered by pull requests from forks, or to Dependabot runs unless you add them separately. The file
authurl.txtends up empty and the login reports an invalid or missing URL. - Wrong secret scope. The secret lives in the
productionenvironment, but the job does not declareenvironment: production, so the value is blank. - Malformed value. An auth URL begins with
force://. A pasted value with extra quotes, a line break, or a truncated token fails. - Expired or revoked token. The user's password was changed, the user was deactivated, the connected app policy changed, or the refresh token was revoked. The error often mentions an expired access or refresh token.
- IP or session policy. GitHub-hosted runners use changing IP addresses. A profile with login IP ranges, or a connected app that restricts IPs, blocks them.
To confirm, generate a new auth URL on your machine and replace the secret:
sf org display --target-org my-prod-alias --verboseWith --verbose, the output includes the Sfdx Auth Url field. Treat it like a password. If the new URL works, the old token was the problem. If you use the JWT bearer flow instead, check that the certificate in the secret matches the one uploaded to the connected app, that the connected app pre-authorizes the user, and that the username is correct.
Deployment errors
If login succeeds and the deploy step fails, the output lists component problems. These are the most frequent messages and their meaning:
| Message pattern | Likely cause | Fix |
|---|---|---|
| `Entity of type 'X' named 'Y' cannot be found` | The package references metadata that is not in the deployment | Add the missing file, or fix the manifest or delta output |
| `Invalid reference` or `No such column` | A field or object is missing in the target org | Deploy the dependency first, or include it in the same change |
| `Dependent class is invalid and needs recompilation` | Another class has a compile error | Fix the class named earlier in the log |
| `This feature is not enabled` | The target org lacks a feature or license | Enable it in the org, or exclude the component |
| `Cannot modify managed object` | You are changing something a managed package controls | Remove it from source |
A deploy that passes in a scratch org and fails in a sandbox often points to a difference in org configuration. Compare enabled features, record types, and installed packages.
To see the full details of a failed deployment, ask the org for its report:
sf project deploy report --use-most-recent --target-org targetYou can also pass --job-id with the ID printed in the log. The report lists each component failure with its file and line.
Test failures and coverage
Test problems appear as Test Failures in the deploy output, or as a failed sf apex run test step. Check these causes:
- Order or data dependence. A test passes alone and fails in the full run because it relies on existing org data or on another test's side effects. Use
@IsTestdata setup, and avoidSeeAllData=true. - Org differences. Validation runs against a sandbox whose data and configuration differ from your scratch org.
- Governor limits. A test that nears limits can fail intermittently when more automation is active in the target org.
- Coverage below the threshold. A deployment to production needs at least 75% overall Apex coverage, and every trigger needs some coverage. A new class without tests can lower the total below the line.
- Time-based logic. Tests that depend on the current date fail on certain days, such as month-end.
Keep the results for later reading. This step saves them even when tests fail:
- name: Run Apex tests
run: >
sf apex run test
--test-level RunLocalTests
--result-format junit
--code-coverage
--output-dir test-results
--wait 30
--target-org target
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: apex-test-results
path: test-resultsThe if: always() condition makes the upload run after a failed test step. Without it, GitHub skips the step exactly when you need the files. To reproduce one failure, run the failing class alone with --tests ClassName (and --test-level RunSpecifiedTests in a deploy).
Timeouts, cancellations, and stuck runs
The --wait 60 flag sets how many minutes the CLI waits for the org. If the wait ends first, the step fails, but the deployment keeps running in Salesforce. This causes two problems:
- A rerun may hit "another deployment is in progress" until the first one finishes.
- A later check shows the first deployment succeeded, and the pipeline reported failure.
Check Setup, Deployment Status, to see what the org is doing. You can follow a running job with sf project deploy resume, or stop it with sf project deploy cancel. Then raise --wait, narrow the deployment with a delta, or reduce the test level for validation runs.
Jobs can also queue on GitHub's side. If you set a concurrency group, as in the production deploy workflow, a waiting run shows "Queued" until the earlier run finishes. This is expected behavior. With cancel-in-progress: false, runs wait. Pending runs in the same group can replace each other, so only the newest waiting run starts.
Problems that come from the pipeline setup
Some failures are not about Salesforce at all.
- Delta deploy finds nothing or the wrong things.
sfdx-git-deltacompares Git revisions. With the default shallow checkout, the base commit is missing. Setfetch-depth: 0inactions/checkout. - Path filters skip the run. If
paths: ['force-app/**']does not match your package directory, the workflow never starts. CheckpackageDirectoriesinsfdx-project.json. - CLI version drift.
npm install --global @salesforce/cliinstalls the latest version. A new release can change flags or output. To get repeatable runs, pin a version, for example@salesforce/[email protected], and update it on purpose. - Plugin install prompts. Unsigned plugins ask for confirmation in interactive use. In CI, check the install step output for this.
Getting more detail
Use these tools in this order:
- Add
--jsonto a failing command and read the structured result. This is easier to inspect than the formatted table, and it keeps the component names intact. - Re-run the job with "Enable debug logging" in the GitHub UI. This turns on step debug output.
- Reproduce locally against a sandbox with the same command and the same flags. A check-only deploy with
--dry-runchanges nothing. - For Apex failures, open the debug log in the org, or read the stack trace in the saved test results.
Never print secrets while debugging. GitHub masks exact secret values in logs, but it cannot mask a changed or partial form of one, such as a Base64 version. Do not cat authurl.txt in a step.
Exercise
A pull request validation run fails at the login step with an invalid auth URL error. The same workflow passed yesterday on a branch in the main repository. This failing run comes from a branch in a contributor's fork. What is the most likely cause, and what is a safe way to validate such pull requests?
Show answer
GitHub does not pass repository secrets to workflows triggered by pull requests from forks, so SFDXAUTHURL is empty and the login fails. A safe approach is to have a maintainer review the code and push it to a branch in the main repository, so the workflow runs with secrets. Do not expose secrets to untrusted fork code.
Exercise
Your deploy step times out after --wait 60, and the next run fails with a message that another deployment is in progress. What happened, and what do you do?
Show answer
The CLI stopped waiting, but the deployment kept running in the org. Check Deployment Status in Setup, or use sf project deploy resume to follow the job, or sf project deploy cancel to stop it. After it ends, rerun the pipeline, and reduce the deployment size with a delta or raise --wait.