Sub topic 18
Troubleshooting failed pipeline runs
This chapter assumes you have read the earlier chapters on authentication, pull request validation, and deploying on merge. You should know what the sf project deploy start command does and where the workflow files live in your repository.
A method for reading a failed run
Most failures fall into a few groups. Work from the top of the log down, and stop at the first step marked red. Later errors are often side effects of that first one.
- Open the failed run in the Actions tab and find the first failed step.
- Read the last 20 lines of that step, not only the final line.
- Decide which group the error belongs to: authentication, deployment, tests, or workflow setup.
- Reproduce it locally with the same
sfcommand when you can.
Authentication errors
Authentication errors appear in the login step. Typical causes:
- The secret is empty or has the wrong name. A job that uses
environment: productionreads that environment's secrets, not the repository ones. - The auth URL is stale. It stops working if the user's password changes or the connected app token is revoked. Generate a new one with
sf org display --verbose --target-org <alias>and update the secret. - The auth URL is for a sandbox but the job targets production, or the reverse.
Never print the secret to debug it. GitHub masks stored secrets in logs, but a modified copy is not masked.
Deployment errors
If login works and the deployment fails, the error names a component. The most common cause is missing metadata. A class references a custom field, a permission set references a class, or a flow references an object, and that dependency is not in the deployed source.
- With a full deployment, add the missing file to
force-app. - With a delta deployment, the dependency did not change, so it was not in the package. Deploy it first, or include it in the delta.
- If the error mentions an API version or a missing feature, compare the target org's edition and settings with your scratch org definition.
Also check the --wait value. If the job ends while the org is still processing, the deployment may still be running in Salesforce. Look at Setup, Deployment Status, before you re-run.
Test failures and coverage
A test failure shows the class, the method, and a stack trace. Check these causes in order:
- The test depends on org data. Tests should create their own records.
- The test depends on another change that is not merged yet.
- Coverage is below 75 percent for a production deployment.
Use sf apex run test --result-format human --code-coverage locally against a scratch org to see which lines lack coverage.
Workflow setup errors
sf: command not found: the CLI install step failed or ran after the step that uses it.fatal: bad objector an empty delta: the checkout used the default shallow history. Setfetch-depth: 0onactions/checkout.- The workflow does not start: check the
on:filters. Apathsfilter onforce-app/**skips changes made elsewhere.
Exercise
A pull request validation job fails with "Required secret SFDXAUTHURL is empty", but you added the secret last week. Where do you look first, and why?
Show answer
Check where the secret was created. If it was added to a GitHub environment, a job without an environment: key cannot read it. If the job uses environment: production, a secret saved only at repository level may be missing from that environment. Match the secret's scope to the job's environment setting.
Exercise
A delta deployment fails because a Apex class cannot find a custom field that exists in production. What happened, and what are two ways to fix it?
Show answer
The delta package contained only the changed class. The field was not part of the change, but the target org you deployed to does not have it yet. Fix it by deploying the field first, or by including the field in the package, for example by changing it in the same pull request. Running a full validation on a schedule also catches this early.