Exit codes
`@@CLI@@ ci run` launches a project's runs, waits for each one to finish and exits with a code your CI job can gate on.
heybug ci run launches a project's runs, waits for each one to finish and exits with a code your CI job can gate on. Exit 0 means every run passed. Any other code fails the step, and the message on stderr says why.
What it is for
A CI job needs one answer: did the tests pass, did they fail, or could nothing be tested. The exit code gives that answer without parsing text. Use the JUnit file when you want the per-test detail in your CI report.
Steps
- Store the server address as
HEYBUG_SERVERand an access token asHEYBUG_TOKEN. Setup is in CI. - Run
heybug ci run --project <id>. Add--target-urlfor the app under test, or--envfor a named environment. - The command prints a line per run,
Run <id>: <dashboard link>, then waits. The wait has no time limit. - Read the exit code. Stop the job on anything except
0. - Optional: add
--report junit --report-file <path>to write a JUnit XML report.
Exit codes
| Code | Name | When it happens | What to do |
|---|---|---|---|
| 0 | Passed | Every run passed. Or the launch selected no tests and --allow-skip was set. | Continue the job. |
| 1 | Failed | A run ended with any status other than passed (failed, error or canceled), or a case failed or errored. | Open the run link and read the failed case. An error status is an infrastructure problem, not a test verdict. |
| 2 | Usage | --project is missing, or --report is not junit. | Fix the flags. |
| 3 | Not signed in | HEYBUG_TOKEN or HEYBUG_SERVER is missing, or the server refused the token. | Check the secrets. Never print the token in the log. |
| 4 | Not found | --env names no environment in the project, or the project does not exist. | Check the environment name and project id. |
| 5 | Invalid input or gate | The launch selected no tests and --allow-skip was not set. Or the --wait-for-status check did not succeed. Or the server rejected the input. | Read the message. See the sections below. |
| 6 | Server or network | The server could not be reached or returned a server error. Also an interrupted wait. | Retry the job. Nothing was decided about the app. |
| 7 | Rate limited | The server asked the client to slow down. | Retry after a short pause. |
| 12 | Credits | The account has no credits left. | Add credits, then run again. |
| 13 | Plan gate | The feature is not in the workspace's plan. | Ask the workspace owner. |
Code 6 is the only one that means "try again". Every other non-zero code needs a change to the input, the setup or the app.
Skipped runs and --allow-skip
A launch is skipped when it selects no tests. The command prints Skipped: no tests were selected. on stderr.
- Without
--allow-skip, a skipped launch exits5. "Nothing was tested" is not a pass. - With
--allow-skip, a skipped launch exits0. Use this only when an empty selection is expected, for example docs-only changes.
--allow-skip changes only that case. A run that fails still exits 1. A --wait-for-status check that did not succeed still exits 5, whether or not the flag is set.
JUnit report
--report junit --report-file <path> writes one testsuite named heybug. Each case becomes a testcase named <case key> <title>. Failed and errored cases carry a failure element with the status and the expected text.
- Without
--report-file, nothing is written.--report junitalone creates no file. - The file is written after each run ends. If its folder does not exist, the command prints
heybug ci run: report: ...on stderr. The exit code does not change. - If one launch starts more than one run, each run overwrites the file. The file then holds the last run.
- A run that ends canceled or error with no failed case has zero failures in the XML and still exits
1. Gate on the exit code, not on the XML.
Example
A GitHub Actions step that tests a preview, keeps the report and branches on the code:
- name: Run HeyBug
env:
HEYBUG_SERVER: ${{ secrets.HEYBUG_SERVER }}
HEYBUG_TOKEN: ${{ secrets.HEYBUG_TOKEN }}
run: |
code=0
heybug ci run --project p_1 --target-url "$PREVIEW_URL" \
--report junit --report-file results/heybug.xml || code=$?
case "$code" in
0) echo "Every test passed." ;;
1) echo "A test failed, errored or was canceled. Open the run link above." ;;
5) echo "Nothing was tested, or a gate was not met. Read the message above." ;;
6) echo "The server could not be reached. Retry the job." ;;
*) echo "Stopped with exit code $code. Read the message above." ;;
esac
exit "$code"Set PREVIEW_URL in an earlier step, and create the results folder before this one, or the report is not saved. The exit code still gates the job either way.
When it fails
- Code 1. Open the link printed as
Run <id>: <url>. Read the first failed case. The JUnit file, if you wrote one, lists the same cases. - Code 5 with
Skipped: no tests were selected.The selection matched nothing. Check the project and environment. Add--allow-skiponly if an empty run is fine. - Code 5 with
check "<name>" ended with <conclusion>ordid not finish in 20 minutes. The check named in--wait-for-statusdid not succeed. Fix that check.--allow-skipdoes not cover it. - Code 5 with
no deployment URL found for this commit.--target-url-from-deploymentfound no deployment for the commit. Pass--target-urlinstead. - Code 4 with
No environment named ... in this project.Check the environment name. Matching ignores case, but the name must match. - Code 3. Check the
HEYBUG_TOKENandHEYBUG_SERVERsecrets, then the token's scopes in CI. - Code 6. Retry the job. Check the server address if the retry fails too.
For the general exit codes of the other CLI commands, see CLI exit codes.