Automate
Load tests in a CI pipeline
Gate a GitHub, GitLab or any other CI pipeline on the verdict of a load test with a ready file of your server.
A CI pipeline (GitHub Actions, GitLab CI/CD, Jenkins...) can run a load test each time you deliver, and stop the delivery when the test does not pass. The job starts the test, waits for its verdict and fails unless the test passed. You do not write this job yourself: your Swarmetry server gives four ready files, with its own address written in.
| File | For | Where it goes |
|---|---|---|
github-workflow.yml |
GitHub Actions: a whole workflow | .github/workflows/swarmetry.yml in your repository |
github-action.yml |
GitHub Actions: a step to add to your own workflows | .github/actions/swarmetry/action.yml in your repository |
gitlab-ci.yml |
GitLab CI/CD: a job | your .gitlab-ci.yml |
swarmetry-ci.sh |
Any other CI (Jenkins, Azure Pipelines, Bitbucket Pipelines...): a shell script | your repository, run with sh swarmetry-ci.sh |
The same files are listed on Help > Developer access (/app/developer), under Use it in a CI pipeline. They use
the command line swarmetry (page 28), which they download from your server.
Before you start
- A test that decides. The verdict comes from the thresholds of the test configuration (Thresholds), for example "95% of the requests answer in less than 500 ms". Without a threshold a test has no verdict, and the job fails with code 22.
- A verified target. The test only sends load to domains your organization has verified (page 4).
- A token for the pipeline. Create a service account with the permissions to start tests and read their
results, and a token of it (page 31). Keep the token (it starts with
sw_sat_) in the secret store of your CI, under the nameSWARMETRY_TOKEN. A personal token also works, but stops working when you leave the organization. - The ids of the test. Open the test configuration in Swarmetry: its address holds the three ids the templates
need,
/app/projects/<project>/scenarios/<scenario>/configs/<test configuration>. With the command line:swarmetry project list,swarmetry scenario list --project-id <id>, thenswarmetry test-config list --project-id <id> --scenario-id <id>. - Allowed IP ranges. If your organization only accepts some addresses (Administration > Security policies), add the addresses of your CI runners. Runners hosted by GitHub or GitLab use many addresses that change: a runner of your own with a fixed address is simpler.
What every template does
- Installs the command line from your server, never from elsewhere, over https only (TLS 1.2 or later, never a
redirect to http), and checks it: against the SHA-256 you pinned in your repository
(Pin the command line, the secure choice), otherwise against the
SHA256SUMSfile of your server, itself verified with Swarmetry's release key once one is published (Checksums and signature). When a check fails, nothing is run. - Starts the test with
-y --wait. A test sends load to your site and uses the quotas of your plan, so the command line asks for a confirmation; a pipeline has no terminal to answer it, and without-ythe start is refused (code 10). By writing-yin your pipeline you confirm every test it starts. - Runs the preflight your organization requires, if it requires one (
--preflight-if-required): when the run policy asks for a passed preflight before a test of this size, the command line runs it first (a short real run with a few virtual users), waits for its result and starts the test with it. A preflight that does not pass ends the job with code 26 and its findings: the test is not started. - Waits for the verdict, at most
SWARMETRY_TIMEOUT(1 hour by default); then it stops the test (code 25). - Writes the JUnit XML of the test,
swarmetry-junit.xml, also when the test fails: the verdict, each threshold and each check are test cases. On GitHub the job summary also shows the verdict and the failed thresholds. - Ends with the code of the verdict and a line that says what it means (table below).
- Notes where the test comes from: the test shows "GitHub Actions acme/shop main 0123abc" (or the GitLab equivalent) in Swarmetry.
- Stops the test when the job is cancelled: the command line stops the test it started, then ends with code 130.
- Never prints the token: the command line reads it from the environment (
SWARMETRY_TOKEN); it is never on a command line or in a file of your repository.
The templates start the test only when you ask (the Run workflow button of GitHub, New pipeline of GitLab). Each file says, in a comment, how to run it on each push to your main branch instead: every test then uses the quotas of your plan.
Pin the command line
By default a template runs the file your server serves at each run, checked against the checksums of that same server. Pinning is the secure choice: you commit in your repository the version and the SHA-256 of the file of your runner, and the job runs that file only. Nobody who could change what your server serves can then run another program in your pipeline. After an upgrade of your server the job stops, says that the server serves another command line and prints the SHA-256 of the new file: check it, then pin the new version in a commit that is reviewed like any other.
-
Open Help > Developer access and note the version and the SHA-256 of the file of your runner:
swarmetry-linux-amd64for the Linux runners of GitHub and GitLab,swarmetry-linux-arm64on ARM runners,swarmetry-darwin-arm64on Apple silicon runners. Its line inSHA256SUMSgives the same SHA-256. -
Write both values in the file of your pipeline, in your repository:
Template Version SHA-256 github-workflow.ymlSWARMETRY_CLI_VERSIONunderenvSWARMETRY_CLI_SHA256underenvgithub-action.ymlinput cli-versioninput cli-sha256gitlab-ci.ymlSWARMETRY_CLI_VERSIONundervariablesSWARMETRY_CLI_SHA256undervariablesswarmetry-ci.shSWARMETRY_CLI_VERSIONSWARMETRY_CLI_SHA256(in the job definition kept in your repository, for example theenvironmentof a Jenkinsfile)For example, in the workflow:
SWARMETRY_CLI_VERSION: 'v4.0.0' SWARMETRY_CLI_SHA256: '<the 64 characters of the page>' -
Commit. Keep the values in the repository, not in the settings of your CI: there they are reviewed like code. On GitLab, a project variable or a variable given when you run a pipeline replaces the job's value: define neither for these names.
With both values set, the job does not read SHA256SUMS at all: the SHA-256 in your repository is what it trusts. One
value without the other is refused (set both); a file of another version is refused too.
GitHub Actions
A workflow
- In your repository, open Settings > Secrets and variables > Actions.
- Under Secrets, add
SWARMETRY_TOKEN: the token of the service account. - Under Variables, add
SWARMETRY_PROJECT_ID,SWARMETRY_SCENARIO_IDandSWARMETRY_TEST_CONFIG_ID. Optional:SWARMETRY_TIMEOUT(for example30m),SWARMETRY_ENVIRONMENT_ID,SWARMETRY_ALLOW_INCONCLUSIVE. - Save the file below as
.github/workflows/swarmetry.yml, push it, then open the Actions tab and choose Load test > Run workflow.
# Swarmetry load test gate for GitHub Actions: a workflow.
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/github-workflow.yml
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# Save it as .github/workflows/swarmetry.yml in your repository. Then, in Settings > Secrets and variables > Actions:
# - secret SWARMETRY_TOKEN: the token of a service account (sw_sat_...), Administration > Service accounts;
# - variables SWARMETRY_PROJECT_ID, SWARMETRY_SCENARIO_ID, SWARMETRY_TEST_CONFIG_ID: the address of the test
# configuration in Swarmetry holds the three ids (/app/projects/<project>/scenarios/<scenario>/configs/<config>).
# The job installs the command line from your server, starts the test with -y (a pipeline has no terminal: -y confirms
# a test that sends load and uses the quotas of your plan), waits for its verdict, writes the job summary and keeps the
# JUnit XML. It fails when the test does not pass. Optional variables: SWARMETRY_ALLOW_INCONCLUSIVE=1 lets an
# inconclusive test pass with a warning, SWARMETRY_TIMEOUT (default 1h).
# The command line is checked against the SHA-256 pinned below (SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256, the
# secure choice: the version and the SHA-256 of swarmetry-linux-amd64 on the page Developer access), otherwise against
# SHA256SUMS of your server, itself verified with Swarmetry's release key when one is written below. Downloads are
# https only, TLS 1.2 or later, never redirected to http.
name: Load test
on:
workflow_dispatch: # the "Run workflow" button of the Actions tab
# push:
# branches: [main] # every push to main: each test uses the quotas of your plan
permissions:
contents: read
jobs:
load-test:
runs-on: ubuntu-latest
timeout-minutes: 90
defaults:
run:
shell: bash
env:
SWARMETRY_URL: 'https://swarmetry.io'
# Pinned command line: for example SWARMETRY_CLI_VERSION 'v4.0.0' and SWARMETRY_CLI_SHA256 '<64 hexadecimal
# characters>'. Empty: the file your server serves.
SWARMETRY_CLI_VERSION: ''
SWARMETRY_CLI_SHA256: ''
SWARMETRY_PROJECT_ID: ${{ vars.SWARMETRY_PROJECT_ID }}
SWARMETRY_SCENARIO_ID: ${{ vars.SWARMETRY_SCENARIO_ID }}
SWARMETRY_TEST_CONFIG_ID: ${{ vars.SWARMETRY_TEST_CONFIG_ID }}
SWARMETRY_ENVIRONMENT_ID: ${{ vars.SWARMETRY_ENVIRONMENT_ID }}
SWARMETRY_TIMEOUT: ${{ vars.SWARMETRY_TIMEOUT || '1h' }}
steps:
- name: Install the Swarmetry command line from your server
env:
# Swarmetry's release key, written in by your server (empty: none).
SWARMETRY_RELEASE_SIGNER: ''
run: |
bin="$RUNNER_TEMP/swarmetry"
mkdir -p "$bin"
case "$(uname -m)" in
x86_64) name=swarmetry-linux-amd64 ;;
aarch64) name=swarmetry-linux-arm64 ;;
*) echo "::error::No command line for the processor $(uname -m)"; exit 1 ;;
esac
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) if [ "$proto" = '=https' ]; then echo "::error::SWARMETRY_URL must be an https address"; exit 1; fi ;;
esac
get() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
get "$SWARMETRY_URL/cli/files/$name" "$bin/$name"
if [ -n "$SWARMETRY_CLI_VERSION$SWARMETRY_CLI_SHA256" ]; then
if [ -z "$SWARMETRY_CLI_VERSION" ] || [ -z "$SWARMETRY_CLI_SHA256" ]; then
echo "::error::Pinned command line: set both SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"; exit 1
fi
got=$(sha256sum "$bin/$name" | cut -d ' ' -f 1)
if [ "$got" != "${SWARMETRY_CLI_SHA256,,}" ]; then
echo "::error title=Command line changed::Your server serves another command line than the one pinned in this workflow (its SHA-256: $got). If your server was upgraded, check the new file on the page Developer access, then update SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
exit 1
fi
else
get "$SWARMETRY_URL/cli/files/SHA256SUMS" "$bin/SHA256SUMS"
if [ -n "$SWARMETRY_RELEASE_SIGNER" ]; then
get "$SWARMETRY_URL/cli/files/SHA256SUMS.sig" "$bin/SHA256SUMS.sig"
printf '%s\n' "$SWARMETRY_RELEASE_SIGNER" > "$bin/allowed_signers"
if ! ssh-keygen -Y verify -f "$bin/allowed_signers" -I swarmetry-cli -n 'cli.swarmetry.io' -s "$bin/SHA256SUMS.sig" < "$bin/SHA256SUMS"; then
echo "::error title=Signature::The signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"
exit 1
fi
fi
(cd "$bin" && awk -v n="$name" '$2 == n' SHA256SUMS | sha256sum -c -)
fi
chmod 0755 "$bin/$name"
mv "$bin/$name" "$bin/swarmetry"
version=$("$bin/swarmetry" --version)
if [ -n "$SWARMETRY_CLI_VERSION" ] && [ "${version##* v}" != "${SWARMETRY_CLI_VERSION#v}" ]; then
echo "::error::The pinned file is $version, not $SWARMETRY_CLI_VERSION: correct SWARMETRY_CLI_VERSION or SWARMETRY_CLI_SHA256"
exit 1
fi
echo "$bin" >> "$GITHUB_PATH"
echo "$version"
- name: Run the load test and wait for its verdict
env:
SWARMETRY_TOKEN: ${{ secrets.SWARMETRY_TOKEN }}
SWARMETRY_ALLOW_INCONCLUSIVE: ${{ vars.SWARMETRY_ALLOW_INCONCLUSIVE }}
run: |
if [ -z "$SWARMETRY_TOKEN" ]; then
echo "::error::The secret SWARMETRY_TOKEN is not set (the token of a service account)"
exit 1
fi
args=(run start --project-id "$SWARMETRY_PROJECT_ID" --scenario-id "$SWARMETRY_SCENARIO_ID")
if [ -n "$SWARMETRY_TEST_CONFIG_ID" ]; then args+=(--test-config-id "$SWARMETRY_TEST_CONFIG_ID"); fi
if [ -n "$SWARMETRY_ENVIRONMENT_ID" ]; then args+=(--environment-id "$SWARMETRY_ENVIRONMENT_ID"); fi
args+=(--note "GitHub Actions $GITHUB_REPOSITORY $GITHUB_REF_NAME ${GITHUB_SHA:0:7}")
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
args+=(--preflight-if-required)
args+=(-y --wait --timeout "$SWARMETRY_TIMEOUT" --stop-on-timeout --junit swarmetry-junit.xml)
# A cancelled workflow signals this shell: pass it on, the command line stops the test it started.
swarmetry "${args[@]}" &
pid=$!
trap 'kill -TERM "$pid" 2>/dev/null || :' INT TERM
code=0
wait "$pid" || code=$?
while kill -0 "$pid" 2>/dev/null; do code=0; wait "$pid" || code=$?; done
case "$code" in
0) exit 0 ;;
20) echo "::error title=Load test failed::A threshold failed, or the test was stopped by a threshold" ;;
21)
if [ "$SWARMETRY_ALLOW_INCONCLUSIVE" = 1 ]; then
echo "::warning title=Load test inconclusive::Nothing failed, but the test cannot be declared passed"
exit 0
fi
echo "::error title=Load test inconclusive::Nothing failed, but the test cannot be declared passed (SWARMETRY_ALLOW_INCONCLUSIVE=1 lets it pass)"
;;
22) echo "::error title=No verdict::The test has no threshold: add thresholds to its test configuration" ;;
23) echo "::error title=Load test stopped::The test was stopped before its end" ;;
24) echo "::error title=Technical failure::The test failed for a technical reason (error code in the log): run the job again" ;;
25) echo "::error title=Timeout::The test was still running after $SWARMETRY_TIMEOUT and was stopped" ;;
26) echo "::error title=Preflight failed::The preflight the run policy requires did not pass (findings in the log), so the test was not started: fix the scenario, then run the job again" ;;
3) echo "::error title=Token refused::The token was refused or has expired: update the secret SWARMETRY_TOKEN" ;;
4) echo "::error title=Refused::The start was refused (error code and hint in the log): a permission of the service account, your plan, an address that is not an allowed target, or the allowed IP ranges of your organization. Do not retry in a loop" ;;
6) echo "::error title=Start refused::A rule of your organization refused the start (error code and hint in the log): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) echo "::error title=Cannot start::The test cannot start as configured (error code and hint in the log): check the ids, the test configuration, its secrets and datasets" ;;
8) echo "::error title=Quota reached::A quota or a limit of your plan is reached. Do not retry in a loop" ;;
11) echo "::error title=Server unreachable::Check SWARMETRY_URL and the network of the runner" ;;
130) echo "::error title=Cancelled::The test this job started was stopped" ;;
*) echo "::error title=Load test::The command line exited with code $code (exit codes in the guide)" ;;
esac
exit "$code"
- name: Keep the JUnit report
if: always()
uses: actions/upload-artifact@v7
with:
name: swarmetry-junit
path: swarmetry-junit.xml
if-no-files-found: ignore
A step for your own workflows (composite action)
Use it when the load test is one step of a workflow you already have, for example after the deployment to a staging
server. Swarmetry does not publish this action on GitHub: you keep a copy in your repository, which your workflows
can always use. Save the file below as
.github/actions/swarmetry/action.yml, then add these steps to a job:
permissions:
contents: read
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/swarmetry
with:
token: ${{ secrets.SWARMETRY_TOKEN }}
project-id: ${{ vars.SWARMETRY_PROJECT_ID }}
scenario-id: ${{ vars.SWARMETRY_SCENARIO_ID }}
test-config-id: ${{ vars.SWARMETRY_TEST_CONFIG_ID }}
actions/checkout comes first because GitHub reads a local action from the checked-out repository. Inputs:
token, project-id, scenario-id (required), test-config-id, environment-id, timeout (1h),
allow-inconclusive ('false'), junit-file (swarmetry-junit.xml), artifact-name (swarmetry-junit, ''
keeps no artifact), url (your server), cli-version and cli-sha256 (see Pin the command line). Output:
exit-code.
# Swarmetry load test gate for GitHub Actions: a composite action to keep in your repository.
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/github-action.yml
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# Save it as .github/actions/swarmetry/action.yml in your repository, then use it in any job, after actions/checkout:
#
# permissions:
# contents: read
# steps:
# - uses: actions/checkout@v7
# - uses: ./.github/actions/swarmetry
# with:
# token: ${{ secrets.SWARMETRY_TOKEN }}
# project-id: ${{ vars.SWARMETRY_PROJECT_ID }}
# scenario-id: ${{ vars.SWARMETRY_SCENARIO_ID }}
# test-config-id: ${{ vars.SWARMETRY_TEST_CONFIG_ID }}
#
# token is the token of a service account (sw_sat_...), Administration > Service accounts, kept as a secret of your
# repository. The action installs the command line from your server, starts the test with -y (a pipeline has no
# terminal: -y confirms a test that sends load and uses the quotas of your plan), waits for its verdict, writes the job
# summary, keeps the JUnit XML as an artifact and fails the step when the test does not pass. Linux and macOS runners.
# The command line is checked against the SHA-256 pinned with the inputs cli-version and cli-sha256 (the secure choice:
# the version and the SHA-256 of the file of your runner on the page Developer access, written in your workflow),
# otherwise against SHA256SUMS of your server, itself verified with Swarmetry's release key when one is written below.
# Downloads are https only, TLS 1.2 or later, never redirected to http.
name: Swarmetry load test
description: Starts a Swarmetry load test, waits for its verdict and fails the step when the test does not pass.
inputs:
token:
description: Token of a Swarmetry service account (sw_sat_...). Pass a secret, never a value written in the workflow.
required: true
project-id:
description: Id of the project of the test.
required: true
scenario-id:
description: Id of the scenario to run.
required: true
test-config-id:
description: Id of the test configuration (load and thresholds). Recommended, the thresholds decide the verdict.
required: false
default: ''
environment-id:
description: Id of an environment of the project.
required: false
default: ''
timeout:
description: Longest wait for the verdict; then the test is stopped (for example 30m, 1h).
required: false
default: 1h
allow-inconclusive:
description: "'true' lets an inconclusive test pass with a warning."
required: false
default: 'false'
junit-file:
description: JUnit XML file written by the command line.
required: false
default: swarmetry-junit.xml
artifact-name:
description: Name of the artifact that keeps the JUnit file ('' keeps none).
required: false
default: swarmetry-junit
cli-version:
description: Pinned command line, with cli-sha256 (for example v4.0.0). Empty, the file your server serves.
required: false
default: ''
cli-sha256:
description: SHA-256 of the pinned file of your runner (swarmetry-linux-amd64 on GitHub's Linux runners).
required: false
default: ''
url:
description: Address of your Swarmetry server.
required: false
default: 'https://swarmetry.io'
outputs:
exit-code:
description: Exit code of the command line (0 pass, 20 fail, 21 inconclusive, 22 no threshold, 23 stopped, 24 technical failure, 25 timeout, 26 required preflight not passed).
value: ${{ steps.run.outputs.exit-code }}
runs:
using: composite
steps:
- name: Install the Swarmetry command line from your server
shell: bash
env:
SWARMETRY_URL: ${{ inputs.url }}
SWARMETRY_CLI_VERSION: ${{ inputs.cli-version }}
SWARMETRY_CLI_SHA256: ${{ inputs.cli-sha256 }}
# Swarmetry's release key, written in by your server (empty: none).
SWARMETRY_RELEASE_SIGNER: ''
run: |
bin="$RUNNER_TEMP/swarmetry"
mkdir -p "$bin"
case "$(uname -s)" in
Linux) os=linux ;;
Darwin) os=darwin ;;
*) echo "::error::This action runs on Linux and macOS runners"; exit 1 ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*) echo "::error::No command line for the processor $(uname -m)"; exit 1 ;;
esac
name="swarmetry-$os-$arch"
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) if [ "$proto" = '=https' ]; then echo "::error::The input url must be an https address"; exit 1; fi ;;
esac
get() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
if command -v sha256sum >/dev/null; then check=(sha256sum -c -); sum=(sha256sum); else check=(shasum -a 256 -c -); sum=(shasum -a 256); fi
get "$SWARMETRY_URL/cli/files/$name" "$bin/$name"
if [ -n "$SWARMETRY_CLI_VERSION$SWARMETRY_CLI_SHA256" ]; then
if [ -z "$SWARMETRY_CLI_VERSION" ] || [ -z "$SWARMETRY_CLI_SHA256" ]; then
echo "::error::Pinned command line: give both cli-version and cli-sha256"; exit 1
fi
got=$("${sum[@]}" "$bin/$name" | cut -d ' ' -f 1)
if [ "$got" != "$(printf '%s' "$SWARMETRY_CLI_SHA256" | tr 'A-F' 'a-f')" ]; then
echo "::error title=Command line changed::Your server serves another command line than the one pinned in your workflow (its SHA-256: $got). If your server was upgraded, check the new file on the page Developer access, then update cli-version and cli-sha256"
exit 1
fi
else
get "$SWARMETRY_URL/cli/files/SHA256SUMS" "$bin/SHA256SUMS"
if [ -n "$SWARMETRY_RELEASE_SIGNER" ]; then
get "$SWARMETRY_URL/cli/files/SHA256SUMS.sig" "$bin/SHA256SUMS.sig"
printf '%s\n' "$SWARMETRY_RELEASE_SIGNER" > "$bin/allowed_signers"
if ! ssh-keygen -Y verify -f "$bin/allowed_signers" -I swarmetry-cli -n 'cli.swarmetry.io' -s "$bin/SHA256SUMS.sig" < "$bin/SHA256SUMS"; then
echo "::error title=Signature::The signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"
exit 1
fi
fi
(cd "$bin" && awk -v n="$name" '$2 == n' SHA256SUMS | "${check[@]}")
fi
chmod 0755 "$bin/$name"
mv "$bin/$name" "$bin/swarmetry"
version=$("$bin/swarmetry" --version)
if [ -n "$SWARMETRY_CLI_VERSION" ] && [ "${version##* v}" != "${SWARMETRY_CLI_VERSION#v}" ]; then
echo "::error::The pinned file is $version, not $SWARMETRY_CLI_VERSION: correct cli-version or cli-sha256"
exit 1
fi
echo "$bin" >> "$GITHUB_PATH"
echo "$version"
- name: Run the load test and wait for its verdict
id: run
shell: bash
env:
SWARMETRY_URL: ${{ inputs.url }}
SWARMETRY_TOKEN: ${{ inputs.token }}
PROJECT_ID: ${{ inputs.project-id }}
SCENARIO_ID: ${{ inputs.scenario-id }}
TEST_CONFIG_ID: ${{ inputs.test-config-id }}
ENVIRONMENT_ID: ${{ inputs.environment-id }}
WAIT_TIMEOUT: ${{ inputs.timeout }}
ALLOW_INCONCLUSIVE: ${{ inputs.allow-inconclusive }}
JUNIT_FILE: ${{ inputs.junit-file }}
run: |
if [ -z "$SWARMETRY_TOKEN" ]; then
echo "::error::The input token is empty: pass the token of a service account from a secret"
exit 1
fi
args=(run start --project-id "$PROJECT_ID" --scenario-id "$SCENARIO_ID")
if [ -n "$TEST_CONFIG_ID" ]; then args+=(--test-config-id "$TEST_CONFIG_ID"); fi
if [ -n "$ENVIRONMENT_ID" ]; then args+=(--environment-id "$ENVIRONMENT_ID"); fi
args+=(--note "GitHub Actions $GITHUB_REPOSITORY $GITHUB_REF_NAME ${GITHUB_SHA:0:7}")
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
args+=(--preflight-if-required)
args+=(-y --wait --timeout "$WAIT_TIMEOUT" --stop-on-timeout --junit "$JUNIT_FILE")
# A cancelled workflow signals this shell: pass it on, the command line stops the test it started.
swarmetry "${args[@]}" &
pid=$!
trap 'kill -TERM "$pid" 2>/dev/null || :' INT TERM
code=0
wait "$pid" || code=$?
while kill -0 "$pid" 2>/dev/null; do code=0; wait "$pid" || code=$?; done
echo "exit-code=$code" >> "$GITHUB_OUTPUT"
case "$code" in
0) exit 0 ;;
20) echo "::error title=Load test failed::A threshold failed, or the test was stopped by a threshold" ;;
21)
if [ "$ALLOW_INCONCLUSIVE" = true ]; then
echo "::warning title=Load test inconclusive::Nothing failed, but the test cannot be declared passed"
exit 0
fi
echo "::error title=Load test inconclusive::Nothing failed, but the test cannot be declared passed (allow-inconclusive: 'true' lets it pass)"
;;
22) echo "::error title=No verdict::The test has no threshold: add thresholds to its test configuration" ;;
23) echo "::error title=Load test stopped::The test was stopped before its end" ;;
24) echo "::error title=Technical failure::The test failed for a technical reason (error code in the log): run the job again" ;;
25) echo "::error title=Timeout::The test was still running after $WAIT_TIMEOUT and was stopped" ;;
26) echo "::error title=Preflight failed::The preflight the run policy requires did not pass (findings in the log), so the test was not started: fix the scenario, then run the job again" ;;
3) echo "::error title=Token refused::The token was refused or has expired: update the secret" ;;
4) echo "::error title=Refused::The start was refused (error code and hint in the log): a permission of the service account, your plan, an address that is not an allowed target, or the allowed IP ranges of your organization. Do not retry in a loop" ;;
6) echo "::error title=Start refused::A rule of your organization refused the start (error code and hint in the log): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) echo "::error title=Cannot start::The test cannot start as configured (error code and hint in the log): check the ids, the test configuration, its secrets and datasets" ;;
8) echo "::error title=Quota reached::A quota or a limit of your plan is reached. Do not retry in a loop" ;;
11) echo "::error title=Server unreachable::Check the address of the server and the network of the runner" ;;
130) echo "::error title=Cancelled::The test this job started was stopped" ;;
*) echo "::error title=Load test::The command line exited with code $code (exit codes in the guide)" ;;
esac
exit "$code"
- name: Keep the JUnit report
if: always() && inputs.artifact-name != ''
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact-name }}
path: ${{ inputs.junit-file }}
if-no-files-found: ignore
Test results in GitHub
Both files keep the JUnit file as an artifact of the run (swarmetry-junit), downloadable from the run's page, and
the command line writes the verdict to the job summary. To see each threshold as a test result in pull requests, add
an action that reads JUnit XML, for example dorny/test-reporter (with reporter: java-junit) or
mikepenz/action-junit-report. They are not part of the templates because they come from other publishers: choose
one, pin it to a version as your policy asks, and give the job checks: write as their documentation says.
GitLab CI/CD
- In your project, open Settings > CI/CD > Variables.
- Add
SWARMETRY_TOKENwith the visibility Masked and hidden, and tick Protect variable (recommended): only pipelines of protected branches and tags receive the token, so a pipeline started on any other branch cannot use it. Run the job on a protected branch (the default branch usually is); on another branch the job says the variable is not set. - Add
SWARMETRY_PROJECT_ID,SWARMETRY_SCENARIO_IDandSWARMETRY_TEST_CONFIG_ID. - Add the job below to your
.gitlab-ci.yml, then run it from Build > Pipelines > New pipeline.
The JUnit file is published as a test report: the pipeline's Tests tab and the merge request's test summary show
the verdict, each threshold and each check. The job uses the alpine image; on a runner without containers (shell
executor), remove the image line and the apk add line, and install curl and the OpenSSH client (ssh-keygen) on the
machine.
# Swarmetry load test gate for GitLab CI/CD: a job.
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/gitlab-ci.yml
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# Add this job to .gitlab-ci.yml (or save it as swarmetry.gitlab-ci.yml and include it with include: local). Then, in
# Settings > CI/CD > Variables:
# - SWARMETRY_TOKEN: the token of a service account (sw_sat_...), Administration > Service accounts. Visibility
# "Masked and hidden", and tick "Protect variable" (recommended): only pipelines of protected branches and tags
# receive the token, so a pipeline of any other branch cannot use it. Run the job on a protected branch;
# - SWARMETRY_PROJECT_ID, SWARMETRY_SCENARIO_ID, SWARMETRY_TEST_CONFIG_ID: the address of the test configuration
# in Swarmetry holds the three ids (/app/projects/<project>/scenarios/<scenario>/configs/<config>).
# The job installs the command line from your server, starts the test with -y (a pipeline has no terminal: -y
# confirms a test that sends load and uses the quotas of your plan), waits for its verdict and publishes the JUnit XML
# in the Tests tab of the pipeline. It fails when the test does not pass; uncomment allow_failure below to let an
# inconclusive test (exit code 21) pass with a warning.
# The command line is checked against the SHA-256 pinned below (SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256, the
# secure choice: the version and the SHA-256 of swarmetry-linux-amd64 on the page Developer access), otherwise against
# SHA256SUMS of your server, itself verified with Swarmetry's release key when one is written below. Downloads are
# https only, TLS 1.2 or later, never redirected to http.
swarmetry-load-test:
stage: test
image: alpine:3.24
timeout: 90m
variables:
SWARMETRY_URL: 'https://swarmetry.io'
SWARMETRY_TIMEOUT: '1h'
# Pinned command line: for example SWARMETRY_CLI_VERSION 'v4.0.0' and SWARMETRY_CLI_SHA256 '<64 hexadecimal
# characters>'. Empty: the file your server serves.
SWARMETRY_CLI_VERSION: ''
SWARMETRY_CLI_SHA256: ''
# Swarmetry's release key, written in by your server (empty: none).
SWARMETRY_RELEASE_SIGNER: ''
rules:
- if: $CI_PIPELINE_SOURCE == "web" # Build > Pipelines > New pipeline
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # every commit on the default branch: each test uses your quotas
# allow_failure:
# exit_codes: [21]
script:
- apk add --no-cache curl openssh-keygen
- |
if [ -z "${SWARMETRY_TOKEN:-}" ]; then
echo "The variable SWARMETRY_TOKEN is not set (the token of a service account; a protected variable reaches protected branches only)"
exit 1
fi
case "$(uname -m)" in
x86_64) name=swarmetry-linux-amd64 ;;
aarch64) name=swarmetry-linux-arm64 ;;
*) echo "No command line for the processor $(uname -m)"; exit 1 ;;
esac
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) if [ "$proto" = '=https' ]; then echo "SWARMETRY_URL must be an https address"; exit 1; fi ;;
esac
get() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
mkdir -p .swarmetry
get "$SWARMETRY_URL/cli/files/$name" ".swarmetry/$name"
if [ -n "$SWARMETRY_CLI_VERSION$SWARMETRY_CLI_SHA256" ]; then
if [ -z "$SWARMETRY_CLI_VERSION" ] || [ -z "$SWARMETRY_CLI_SHA256" ]; then
echo "Pinned command line: set both SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"; exit 1
fi
echo "$(printf '%s' "$SWARMETRY_CLI_SHA256" | tr 'A-F' 'a-f') .swarmetry/$name" | sha256sum -c - || {
echo "Your server serves another command line than the one pinned in this job (its SHA-256: $(sha256sum ".swarmetry/$name" | cut -d ' ' -f 1)). If your server was upgraded, check the new file on the page Developer access, then update SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
exit 1
}
else
get "$SWARMETRY_URL/cli/files/SHA256SUMS" .swarmetry/SHA256SUMS
if [ -n "$SWARMETRY_RELEASE_SIGNER" ]; then
get "$SWARMETRY_URL/cli/files/SHA256SUMS.sig" .swarmetry/SHA256SUMS.sig
printf '%s\n' "$SWARMETRY_RELEASE_SIGNER" > .swarmetry/allowed_signers
ssh-keygen -Y verify -f .swarmetry/allowed_signers -I swarmetry-cli -n 'cli.swarmetry.io' -s .swarmetry/SHA256SUMS.sig < .swarmetry/SHA256SUMS || {
echo "The signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"; exit 1
}
fi
(cd .swarmetry && awk -v n="$name" '$2 == n' SHA256SUMS | sha256sum -c -)
fi
chmod 0755 ".swarmetry/$name"
mv ".swarmetry/$name" .swarmetry/swarmetry
version=$(.swarmetry/swarmetry --version)
if [ -n "$SWARMETRY_CLI_VERSION" ] && [ "${version##* v}" != "${SWARMETRY_CLI_VERSION#v}" ]; then
echo "The pinned file is $version, not $SWARMETRY_CLI_VERSION: correct SWARMETRY_CLI_VERSION or SWARMETRY_CLI_SHA256"; exit 1
fi
echo "$version"
- |
set -- run start --project-id "$SWARMETRY_PROJECT_ID" --scenario-id "$SWARMETRY_SCENARIO_ID"
if [ -n "${SWARMETRY_TEST_CONFIG_ID:-}" ]; then set -- "$@" --test-config-id "$SWARMETRY_TEST_CONFIG_ID"; fi
if [ -n "${SWARMETRY_ENVIRONMENT_ID:-}" ]; then set -- "$@" --environment-id "$SWARMETRY_ENVIRONMENT_ID"; fi
set -- "$@" --note "GitLab CI $CI_PROJECT_PATH $CI_COMMIT_REF_NAME $CI_COMMIT_SHORT_SHA"
code=0
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
set -- "$@" --preflight-if-required
.swarmetry/swarmetry "$@" -y --wait --timeout "$SWARMETRY_TIMEOUT" --stop-on-timeout --junit swarmetry-junit.xml || code=$?
case "$code" in
0) echo "The test passed" ;;
20) echo "The test failed: a threshold failed, or the test was stopped by a threshold" ;;
21) echo "The test is inconclusive: nothing failed, but it cannot be declared passed (allow_failure exit_codes [21] lets it pass)" ;;
22) echo "The test has no threshold: add thresholds to its test configuration" ;;
23) echo "The test was stopped before its end" ;;
24) echo "Technical failure of the test (error code above): run the job again" ;;
25) echo "The test was still running after $SWARMETRY_TIMEOUT and was stopped" ;;
26) echo "The preflight the run policy requires did not pass (findings above), so the test was not started: fix the scenario, then run the job again" ;;
3) echo "The token was refused or has expired: update the variable SWARMETRY_TOKEN" ;;
4) echo "The start was refused (error code and hint above): a permission of the service account, your plan, an address that is not an allowed target, or the allowed IP ranges of your organization. Do not retry in a loop" ;;
6) echo "A rule of your organization refused the start (error code and hint above): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) echo "The test cannot start as configured (error code and hint above): check the ids, the test configuration, its secrets and datasets" ;;
8) echo "A quota or a limit of your plan is reached. Do not retry in a loop" ;;
11) echo "The server cannot be reached: check SWARMETRY_URL and the network of the runner" ;;
130) echo "Cancelled: the test this job started was stopped" ;;
*) echo "The command line exited with code $code (exit codes in the guide)" ;;
esac
exit "$code"
artifacts:
when: always
expire_in: 30 days
paths:
- swarmetry-junit.xml
reports:
junit: swarmetry-junit.xml
Any other CI
The shell script works in any CI that runs a shell on Linux or macOS: Jenkins, Azure Pipelines, Bitbucket Pipelines,
CircleCI, or a scheduled task. Save it in your repository, give the variables listed at its top to the job (the token
from the CI's secret store, for example a credential bound to SWARMETRY_TOKEN in Jenkins), and run
sh swarmetry-ci.sh. It needs curl, sha256sum or shasum, and ssh-keygen (OpenSSH 8.1 or later) once a release key is
published. It no longer falls back to wget: on a machine without curl (a minimal Alpine Linux image, for example),
install it first (apk add curl). It reuses the command line already
installed in .swarmetry/bin while its checksum matches your server's, so a machine that keeps its workspace
downloads it once per version.
#!/bin/sh
# Swarmetry load test gate for any CI (Jenkins, Azure Pipelines, Bitbucket Pipelines, CircleCI, a cron job...).
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/swarmetry-ci.sh
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# 1. Downloads the swarmetry command line of this computer from your server and checks it: against the SHA-256 you
# pinned (pinned_version and pinned_sha256 below, the secure choice), otherwise against SHA256SUMS of your server,
# itself verified with Swarmetry's release key when one is written below.
# 2. Starts the test and waits for its verdict. -y confirms the start: a test sends load to your site and uses the
# quotas of your plan, and a pipeline has no terminal to ask you. When the run policy of your organization requires a
# passed preflight, the command line runs it first and starts the test with it (--preflight-if-required).
# 3. Writes the JUnit XML of the test for the test report of your CI, also when the test fails.
# 4. Exits 0 when the test passes, otherwise with the code of the command line (explained in the log).
#
# Set these variables in your CI. Keep the token in the secret store of your CI, never in a file of your repository.
# SWARMETRY_TOKEN (secret) token of a service account, sw_sat_..., Administration > Service accounts
# SWARMETRY_PROJECT_ID project of the test
# SWARMETRY_SCENARIO_ID scenario to run
# SWARMETRY_TEST_CONFIG_ID test configuration (load and thresholds). Recommended: the thresholds decide the verdict.
# The address of a test configuration in Swarmetry holds the three ids:
# /app/projects/<project>/scenarios/<scenario>/configs/<test configuration>
# Optional:
# SWARMETRY_ENVIRONMENT_ID environment of the project (base URL, variables)
# SWARMETRY_TIMEOUT longest wait, then the test is stopped (default 1h)
# SWARMETRY_JUNIT JUnit file (default swarmetry-junit.xml)
# SWARMETRY_SUMMARY summary file, JSON (default swarmetry-summary.json)
# SWARMETRY_NOTE note shown with the test in Swarmetry (default: CI)
# SWARMETRY_ALLOW_INCONCLUSIVE=1 an inconclusive test passes with a warning (default: it fails the job)
# SWARMETRY_ALLOW_NO_VERDICT=1 a test without thresholds passes (default: it fails the job)
# SWARMETRY_INSTALL_DIR folder of the command line (default .swarmetry/bin, reused while its checksum matches)
# SWARMETRY_URL your Swarmetry server (default: the address below; https only)
#
# Pinned command line (recommended): write below the version and the SHA-256 of the file of your CI machine (page
# Developer access of Swarmetry, or its line of SHA256SUMS), and commit this file. The job then runs only that file,
# whatever your server serves; after an upgrade of your server it stops and prints the new SHA-256 to check and pin.
#
# Run it with: sh swarmetry-ci.sh
# POSIX sh (dash, bash, BusyBox). Needs curl, sha256sum or shasum, and ssh-keygen (OpenSSH 8.1 or later) when a
# release key is written below. Linux and macOS. Downloads are https only, TLS 1.2 or later, never redirected to http.
# The token is read from the environment by the command line: this script never prints it.
# The whole script is the function main, called on its last line: a file cut short runs nothing.
main() {
set -eu
SWARMETRY_URL="${SWARMETRY_URL:-https://swarmetry.io}"
# Pinned command line (the secure choice): the version and the SHA-256 of the file of your CI machine, for example
# pinned_version='v4.0.0' and pinned_sha256='<64 hexadecimal characters>'. Empty: the file your server serves.
pinned_version="${SWARMETRY_CLI_VERSION:-}"
pinned_sha256="${SWARMETRY_CLI_SHA256:-}"
# Swarmetry's release key, written in by your server (empty: none): SHA256SUMS is verified with it.
release=''
: "${SWARMETRY_TOKEN:?is not set: add the token of a service account as a secret variable of your CI}"
: "${SWARMETRY_PROJECT_ID:?is not set: the id of the project of the test}"
: "${SWARMETRY_SCENARIO_ID:?is not set: the id of the scenario to run}"
export SWARMETRY_URL SWARMETRY_TOKEN
timeout="${SWARMETRY_TIMEOUT:-1h}"
junit="${SWARMETRY_JUNIT:-swarmetry-junit.xml}"
summary="${SWARMETRY_SUMMARY:-swarmetry-summary.json}"
bin="${SWARMETRY_INSTALL_DIR:-.swarmetry/bin}"
say() { printf 'swarmetry-ci: %s\n' "$1" >&2; }
fail() {
say "$1"
exit 1
}
# 1. The command line of this computer, from your server: the pinned file, or the file of SHA256SUMS (verified
# with the release key when there is one).
case "$(uname -s)" in
Linux) os=linux ;;
Darwin) os=darwin ;;
*) fail "this script runs on Linux and macOS (this system is $(uname -s))" ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*) fail "no command line for the processor $(uname -m) (amd64 and arm64 only)" ;;
esac
name="swarmetry-$os-$arch"
files="$SWARMETRY_URL/cli/files"
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) [ "$proto" != '=https' ] || fail "SWARMETRY_URL must be an https address ($SWARMETRY_URL)" ;;
esac
command -v curl >/dev/null 2>&1 || fail "curl is needed to download the command line"
fetch() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
if command -v sha256sum >/dev/null 2>&1; then
sha256() { sha256sum "$1" | cut -d ' ' -f 1; }
elif command -v shasum >/dev/null 2>&1; then
sha256() { shasum -a 256 "$1" | cut -d ' ' -f 1; }
else
fail "sha256sum or shasum is needed to check the download"
fi
mkdir -p "$bin"
if [ -n "$pinned_version$pinned_sha256" ]; then
[ -n "$pinned_version" ] && [ -n "$pinned_sha256" ] ||
fail "pinned command line: set both SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
sum=$(printf '%s' "$pinned_sha256" | tr 'A-F' 'a-f')
how="pinned $pinned_version, SHA-256 verified"
else
fetch "$files/SHA256SUMS" "$bin/SHA256SUMS" || fail "cannot download $files/SHA256SUMS"
how="checksum verified"
if [ -n "$release" ]; then
command -v ssh-keygen >/dev/null 2>&1 ||
fail "ssh-keygen (OpenSSH 8.1 or later) is needed to verify the signature of SHA256SUMS: install the OpenSSH client"
fetch "$files/SHA256SUMS.sig" "$bin/SHA256SUMS.sig" ||
fail "cannot download $files/SHA256SUMS.sig: your server does not sign its checksums, nothing was run"
printf '%s\n' "$release" >"$bin/allowed_signers"
ssh-keygen -Y verify -f "$bin/allowed_signers" -I swarmetry-cli -n 'cli.swarmetry.io' \
-s "$bin/SHA256SUMS.sig" <"$bin/SHA256SUMS" >/dev/null 2>&1 ||
fail "the signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"
how="checksum and signature verified"
fi
sum=$(awk -v n="$name" '$2 == n { print $1 }' "$bin/SHA256SUMS")
[ -n "$sum" ] || fail "$name is not listed in SHA256SUMS of $SWARMETRY_URL"
fi
if [ -x "$bin/swarmetry" ] && [ "$(sha256 "$bin/swarmetry")" = "$sum" ]; then
say "command line already installed in $bin ($how)"
else
fetch "$files/$name" "$bin/$name" || fail "cannot download $files/$name"
got=$(sha256 "$bin/$name")
if [ "$got" != "$sum" ]; then
rm -f "$bin/$name"
[ -z "$pinned_sha256" ] ||
fail "your server serves another command line than the one pinned here (SHA-256 $got, pinned $sum): nothing was run. If your server was upgraded, check the new file on the page Developer access, then update SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
fail "the checksum of $name does not match SHA256SUMS: nothing was run (download again; if it fails again, contact Swarmetry support)"
fi
chmod 0755 "$bin/$name"
mv -f "$bin/$name" "$bin/swarmetry"
say "installed $("$bin/swarmetry" --version) in $bin ($how)"
fi
if [ -n "$pinned_version" ]; then
got=$("$bin/swarmetry" --version)
got=${got##* }
[ "${got#v}" = "${pinned_version#v}" ] ||
fail "the pinned file is version $got, not $pinned_version: correct SWARMETRY_CLI_VERSION or SWARMETRY_CLI_SHA256"
fi
# 2. Start the test and wait for its verdict.
set -- run start --project-id "$SWARMETRY_PROJECT_ID" --scenario-id "$SWARMETRY_SCENARIO_ID"
if [ -n "${SWARMETRY_TEST_CONFIG_ID:-}" ]; then set -- "$@" --test-config-id "$SWARMETRY_TEST_CONFIG_ID"; fi
if [ -n "${SWARMETRY_ENVIRONMENT_ID:-}" ]; then set -- "$@" --environment-id "$SWARMETRY_ENVIRONMENT_ID"; fi
if [ "${SWARMETRY_ALLOW_NO_VERDICT:-0}" = 1 ]; then set -- "$@" --allow-no-verdict; fi
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
set -- "$@" --note "${SWARMETRY_NOTE:-CI}" --preflight-if-required
set -- "$@" -y --wait --timeout "$timeout" --stop-on-timeout --junit "$junit" --summary-json "$summary"
# A cancelled job stops the test it started: the CI signals this shell, which passes the signal on to the command
# line (it stops the test, then exits 130).
"$bin/swarmetry" "$@" &
pid=$!
trap 'kill -TERM "$pid" 2>/dev/null || :' INT TERM
code=0
wait "$pid" || code=$?
while kill -0 "$pid" 2>/dev/null; do
code=0
wait "$pid" || code=$?
done
trap - INT TERM
# 3. What the exit code means for this pipeline.
case "$code" in
0) say "the test passed" ;;
20) say "the test failed: a threshold failed, or the test was stopped by a threshold (see the summary above)" ;;
21)
if [ "${SWARMETRY_ALLOW_INCONCLUSIVE:-0}" = 1 ]; then
say "warning: the test is inconclusive (reasons above); SWARMETRY_ALLOW_INCONCLUSIVE=1 lets the job pass"
exit 0
fi
say "the test is inconclusive: nothing failed, but it cannot be declared passed (reasons above). SWARMETRY_ALLOW_INCONCLUSIVE=1 lets it pass"
;;
22) say "the test has no threshold, so no verdict: add thresholds to its test configuration, or set SWARMETRY_ALLOW_NO_VERDICT=1" ;;
23) say "the test was stopped before its end, by a person, an emergency stop or a limit (see the summary above)" ;;
24) say "technical failure of the test (error code above): run the job again; if it fails again, tell your administrator" ;;
25) say "the test was still running after $timeout and was stopped: raise SWARMETRY_TIMEOUT or shorten the test" ;;
26) say "the preflight the run policy requires did not pass (findings above), so the test was not started: fix the scenario, then run the job again" ;;
3) say "the token was refused or has expired: create a token of the service account and update the secret of your CI" ;;
4) say "the start was refused (error code and hint above): a permission of the service account, your plan, an address that is not an allowed target, or your organization's allowed IP ranges. Do not retry in a loop" ;;
6) say "the start was refused by a rule of your organization (error code and hint above): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) say "the test cannot start as configured (error code and hint above): check the ids, the test configuration, its secrets and datasets" ;;
8) say "a quota or a limit of your plan is reached, or too many requests (error code above). Do not retry in a loop" ;;
11) say "the server cannot be reached: check SWARMETRY_URL and the network of this runner" ;;
130) say "interrupted: the test this job started was stopped" ;;
*) say "the command line exited with code $code (see the exit codes in the guide)" ;;
esac
exit "$code"
}
main "$@"
What the job answers
| Code | The test | What to do |
|---|---|---|
| 0 | Passed | Nothing |
| 20 | Failed: a threshold failed, or the test was stopped by a threshold | Open the test (link in the log) and look at the failed thresholds |
| 21 | Inconclusive: nothing failed, but it cannot be declared passed (lost measurements, a threshold without data) | Read the reasons in the log; see below to let it pass |
| 22 | No verdict: the test configuration has no threshold | Add thresholds, or let it pass with --allow-no-verdict (SWARMETRY_ALLOW_NO_VERDICT=1 in the shell script) |
| 23 | Stopped before its end, by a person, an emergency stop or a limit | Run it again when the reason is gone |
| 24 | Technical failure (error code in the log) | Run the job again; if it fails again, tell your administrator |
| 25 | Still running after SWARMETRY_TIMEOUT, then stopped |
Raise the timeout, or shorten the test |
| 26 | The preflight your organization requires did not pass: the test was not started | Read the findings in the log (and on the page of the preflight), fix the scenario, run the job again |
| 3 | The token was refused or has expired | Create a token of the service account and update the secret |
| 4 | Refused: a permission of the service account, your plan, an address that is not an allowed target, or your organization's allowed IP ranges | Read the error code and the hint: line in the log; do not retry in a loop |
| 6 | Refused by a rule of your organization: an approval is required, or the required preflight could not be used | Read the error code and the hint: line; see Checks and approvals at start; do not retry in a loop |
| 7 | The test cannot start as configured: an id, the test configuration, a secret or a dataset | Read the error code and the hint: line, then fix the test |
| 8 | A quota or a limit of your plan is reached, or too many requests | Wait, or change your plan (page 24); do not retry in a loop |
| 11 | The server cannot be reached | Check the address and the network of the runner |
| 130 | The job was cancelled | The test it started was stopped |
Every code of the command line is listed in Exit codes. A refused start prints its error code
(for example Error: approval.required (HTTP 409)) and, for the usual refusals, a hint: line that says what to do.
To keep the report of the test with the build, add --report-file swarmetry-report.pdf to the command of the
template (it generates the report, which uses one report of your plan, and saves it), then keep that file as an
artifact like the JUnit file.
Letting an inconclusive test pass
By default an inconclusive test fails the job: it did not prove that your site holds the load. To let it pass with a
warning, set SWARMETRY_ALLOW_INCONCLUSIVE=1 (shell script and GitHub workflow), allow-inconclusive: 'true'
(GitHub composite action), or uncomment allow_failure: exit_codes: [21] in the GitLab job (the job then shows a
warning). The JUnit file still shows the verdict as an error, and the test page in Swarmetry says why.
Costs, quotas and refusals
- Each test the pipeline starts counts like a test started from the app: runs, virtual-user hours and the other quotas of your plan. Start load tests on the deliveries that need them, not on every commit.
- The templates never retry a refused start. A quota (code 8), your plan (code 4) or a missing approval (code 6) will refuse the next attempt too: retrying in a loop only fills the logs.
- When your administrators require an approval above a size of test, a large test started by a pipeline is refused (code 6) until that start is approved. For a large test that runs regularly, a schedule, approved once, is the better tool (Approval of a schedule).
- A token that expires during a long test makes the wait end with code 3 while the test goes on in Swarmetry. Rotate the token with an overlap longer than your longest test (page 31).