Azure Pipelines
Upload test results from Azure Pipelines to Qualflare with the qf CLI: azure-pipelines.yml steps, a secret QF_TOKEN variable, and setting QF_BRANCH.
Last updated
To upload test results from Azure Pipelines to Qualflare, add a step that runs qf <identifier> collect <report> after your tests, with the access token in a secret variable named QF_TOKEN; qf reads no Azure variables, so set QF_BRANCH yourself.
Before you begin
- A project access token with Allow writes off, which you create in Project Settings > Access Tokens Editor+ · project (requires the Editor role or higher in the project). See Access Tokens.
- A report file your test step writes, such as JUnit XML. The examples use
cias the identifier.
Store the token as a secret variable
- Go to your project Pipelines > Library
- Go to Variable groups, create or select a group, for example
qualflare - Add variable:
QF_TOKEN, value: Your Qualflare access token - Mark as Secret: Checked
- Click Save
Then reference the group in the YAML, as - group: qualflare does in the pipeline below.
Add the upload step
Add to your azure-pipelines.yml:
trigger:
branches:
include:
- main
- develop
variables:
- group: qualflare # the variable group that holds QF_TOKEN
- name: QF_ENVIRONMENT
value: 'staging' # must be an environment that exists in the project
stages:
- stage: Test
jobs:
- job: TestAndReport
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
displayName: 'Checkout code'
- script: |
VERSION=0.4.0
curl -L "https://github.com/qualflare/qualflare-cli/releases/download/v${VERSION}/qf_${VERSION}_linux_amd64.tar.gz" -o qf.tar.gz
tar -xzf qf.tar.gz && sudo mv qf /usr/local/bin/
displayName: 'Install qf CLI'
- script: pytest --junitxml=results.xml
displayName: 'Run tests'
- script: |
BRANCH="${SYSTEM_PULLREQUEST_SOURCEBRANCH:-$BUILD_SOURCEBRANCH}"
export QF_BRANCH="${BRANCH#refs/heads/}"
qf login ci --force
qf ci collect results.xml
env:
QF_TOKEN: $(QF_TOKEN) # secret variables reach a script only through env
displayName: 'Upload results to Qualflare'
condition: always()See the official Azure Pipelines documentation for azure-pipelines.yml syntax and pipeline concepts beyond what's shown here.
Branch and commit
qf reads no Azure variable, and the Azure checkout is a detached HEAD, so qf finds the commit through local git and no branch. The first two lines of the upload script set QF_BRANCH from Build.SourceBranch, or from System.PullRequest.SourceBranch on a pull request build, without the refs/heads/ prefix. Setting QF_COMMIT: $(Build.SourceVersion) in env: is optional: it is the same commit.
Run the upload when tests fail
condition: always() on the upload step runs it when the test step fails.
Parallel jobs
One qf <identifier> collect call is one launch, and several files in one call merge into it. With the Azure parallel strategy, each copy of the test job writes its own report, and one later job uploads them all with --shard. By default, a job that depends on another runs only when that job succeeds, and condition: always() on a step doesn't carry over to a later job. condition: succeededOrFailed() runs a step or a job after a failure but not after a cancel, so set it on the step that publishes each copy's report as a pipeline artifact and on the upload job.
pool:
vmImage: 'ubuntu-latest'
variables:
- group: qualflare # the variable group that holds QF_TOKEN
- name: QF_ENVIRONMENT
value: 'staging' # must be an environment that exists in the project
jobs:
- job: Test
strategy:
parallel: 2
steps:
- script: |
TESTS=$(find tests -name 'test_*.py' | sort | sed -n "${SYSTEM_JOBPOSITIONINPHASE}~${SYSTEM_TOTALJOBSINPHASE}p")
pytest $TESTS --junitxml=test-results/results.xml
displayName: 'Run tests'
- publish: test-results
artifact: results-$(System.JobPositionInPhase)
condition: succeededOrFailed() # keep the report when the tests fail
- job: Upload
dependsOn: Test
condition: succeededOrFailed() # upload after failed test jobs too
steps:
- checkout: none
- download: current
- script: |
VERSION=0.4.0
curl -L "https://github.com/qualflare/qualflare-cli/releases/download/v${VERSION}/qf_${VERSION}_linux_amd64.tar.gz" -o qf.tar.gz
tar -xzf qf.tar.gz && sudo mv qf /usr/local/bin/
displayName: 'Install qf CLI'
- script: |
BRANCH="${SYSTEM_PULLREQUEST_SOURCEBRANCH:-$BUILD_SOURCEBRANCH}"
export QF_BRANCH="${BRANCH#refs/heads/}"
qf login ci --force
qf ci collect "$PIPELINE_WORKSPACE/results-*/results.xml" --shard
env:
QF_TOKEN: $(QF_TOKEN) # secret variables reach a script only through env
QF_COMMIT: $(Build.SourceVersion)
displayName: 'Upload results to Qualflare'Each copy runs its share of the test files, picked by System.JobPositionInPhase and System.TotalJobsInPhase, and names its artifact after its position. The upload job downloads every artifact into a folder of its own under $PIPELINE_WORKSPACE. It skips the checkout, so the commit comes from QF_COMMIT: $(Build.SourceVersion) in env:, not from local git. qf <identifier> collect exits 0 when the upload succeeds, so the failed test jobs stay failed, and a failed upload fails the upload job. See Sharded runs.
Pin the qf version
The example installs qf 0.4.0 through VERSION=0.4.0. To pin another release, set VERSION to a version from the qf releases page.
Troubleshooting
Error: token cannot be empty means QF_TOKEN didn't reach the script: map it in the step's env:. If qf login succeeds but the upload then fails with a 401 (exit code 3), check that the variable group is linked in variables:: Azure passes an unresolved $(QF_TOKEN) on as that literal text, and qf saves it as the token. Launches with no branch: keep the two QF_BRANCH lines at the top of the upload script. More fixes: Troubleshooting on CI/CD integration.
Related
- Guides: CI/CD integration
- Reference: Upload results with qf collect · Configuration
- CLI/API: Access Tokens
Jenkins
Upload test results from a Jenkins pipeline to Qualflare with the qf CLI: a Jenkinsfile stage, a QF_TOKEN secret text credential and GIT_BRANCH detection.
CircleCI
Upload test results from CircleCI to Qualflare with the qf CLI: a config.yml step that runs when tests fail, a QF_TOKEN variable, and QF_BRANCH from CircleCI.