Metadata-Version: 2.4
Name: qmpass-cli
Version: 0.3.0
Summary: Run Qmpass release gate evaluations and report builds and deployments from your CI/CD pipeline.
Author: Qmpass
License-Expression: LicenseRef-Proprietary
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx==0.28.1
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: ruff>=0.6.0; extra == "dev"
Dynamic: license-file

# Qmpass CLI

Run a [Qmpass](https://qmpass.ai) release gate evaluation from your CI/CD pipeline. The pipeline
deploys a release candidate, `qmpass-cli` evaluates the stage's gate, and the job passes or fails on
the gate's automated checks. Manual checks stay open in Qmpass for your testers — the pipeline never
waits for them.

It also reports what the pipeline **built and deployed** (`qmpass-cli signal push`), so the release
decision in Qmpass shows failed builds and deployments, and a new build on a stage after its sign-off.

## Requirements

- Python 3.10 or newer
- A project API token with **write** access: **Project settings → API tokens** (Pro plan and up)
- For `--agent auto` (the default): Docker on the runner. Otherwise, an agent your team runs (see "Which agent runs the checks"
  below).

## Install

```bash
pipx install qmpass-cli
```

Use pipx (or `pipx run`) so the CLI gets its own environment and never clashes with your job's
packages. Pin the version in pipelines (`qmpass-cli==0.3.0`) to upgrade on your schedule.

## Run

```bash
export QMPASS_TOKEN=qmp_proj_…      # keep it in your CI secrets
qmpass-cli gate evaluate --release 10023 --stage PST-02
```

Name the gate by its ref (`--gate PGT-0007`, shown at the end of the gate page's breadcrumb) or by
release id + stage ref (`--release 10023 --stage PST-02`, stage refs are in Project settings →
Release stages). The evaluation tests the stage's **App Address**.

| Option | Default | |
|---|---|---|
| `--agent` | `auto` | `auto` starts a temporary agent in Docker on the runner and removes it afterwards. Or the name of an agent your team runs (it must be online). |
| `--timeout` | `45m` | Stop waiting and cancel the evaluation. |
| `--no-wait` | | Start and exit 0 (named agents only). |
| `--name` | `<pipeline> #<build number>` | Evaluation name in Qmpass. |
| `--build-version`, `--commit`, `--branch`, `--build-url` | from the CI environment | Shown on the Evaluation page. |
| `--idempotency-key` | the CI run id | Same key = same evaluation, so a re-run of the job doesn't start a second one. |
| `--agent-image` | the release this CLI was tested with | Another agent image (env `QMPASS_AGENT_IMAGE`). |
| `--agent-variant rpa` | | The agent image with the RPA framework (Salesforce, Excel, PDF, Email, …). |

`QMPASS_URL` defaults to `https://api.qmpass.ai`.

## Which agent runs the checks

The CLI only needs the **project API token** (`QMPASS_TOKEN`). It never needs an agent token.

**`--agent auto` (default) — a temporary agent on the runner**

```bash
qmpass-cli gate evaluate --release 10023 --stage PST-02
```

1. The CLI starts the evaluation; Qmpass creates a temporary agent for this evaluation only.
2. The CLI runs the Qmpass test agent image with `docker run` on the runner.
3. The agent connects to Qmpass, runs the gate's automated checks and reports the results.
4. When the checks are done, Qmpass removes the agent and its token, and the container stops.

Needs Docker on the runner. The agent runs on the runner, so it reaches whatever the runner reaches —
preview deploys, or internal URLs on self-hosted runners. Use `--agent-variant rpa` when the gate's
runbooks use the RPA framework.

**`--agent "<name>"` — an agent your team runs**

```bash
qmpass-cli gate evaluate --release 10023 --stage PST-02 --agent "QA runner"
```

The checks run on an agent you installed and connected beforehand (`pipx install qmpass-test-agent`,
then `qmpass-agent run` with that agent's own token from **Project settings → Agents**). It must be
online when the evaluation starts, otherwise the CLI stops with exit code 3. Use it when:

- the runner has no Docker;
- the app under test is reachable only from a particular machine (private network, VPN);
- the checks need a desktop or Windows machine.

With a named agent, `--no-wait` starts the evaluation and exits straight away; follow it in Qmpass.

Either way the CLI waits only for the automated checks — manual checks stay open in Qmpass for your
testers.

Build details are read from GitHub Actions, Bitbucket Pipelines, GitLab CI, Jenkins and Azure
Pipelines.

### Exit codes

| Code | Meaning |
|---|---|
| `0` | The automated checks passed. Manual checks may still be open in Qmpass. |
| `1` | An automated check failed, was blocked or couldn't run. |
| `3` | Setup or infrastructure: token, gate not found, agent offline or not started, Docker missing, timeout, evaluation abandoned. |

Qmpass is an advisory gate: if you don't want a failed check to fail the job, allow the step to fail
(`continue-on-error` / `allow_failure`).

The CLI prints progress and a summary with the failed checks and a link to the evaluation, and writes
`qmpass-evaluation.json`. On GitHub Actions it also writes the job summary and the step outputs
`evaluation`, `state`, `outcome` and `url`.

## In your pipeline

Two commands in any CI: install the CLI, then evaluate. Keep `QMPASS_TOKEN` in your CI's secrets — the token
belongs to one project, so nothing else is needed. `--agent auto` (the default) needs Docker on the runner.

GitHub Actions (`ubuntu-*` runners have pipx and Docker):

```yaml
- name: Qmpass gate
  run: |
    pipx install qmpass-cli==0.3.0
    qmpass-cli gate evaluate --release 10023 --stage PST-02 --build-version "${{ github.ref_name }}"
  env:
    QMPASS_TOKEN: ${{ secrets.QMPASS_TOKEN }}
```

On GitHub the CLI also writes the job summary and the step outputs `evaluation`, `state`, `outcome`, `url`.

Bitbucket Pipelines (secured repository variable `QMPASS_TOKEN`; the `docker` service runs the temporary agent):

```yaml
- step:
    name: Qmpass gate
    image: python:3.12
    services: [docker]
    script:
      - python3 -m pip install pipx
      - python3 -m pipx run --spec qmpass-cli==0.3.0 qmpass-cli gate evaluate --release 10023 --stage PST-02
```

GitLab CI (masked CI/CD variable `QMPASS_TOKEN`; Docker-in-Docker for the agent):

```yaml
qmpass-gate:
  image: python:3.12
  services: [docker:dind]
  variables: { DOCKER_HOST: "tcp://docker:2375" }
  script:
    - python3 -m pip install pipx
    - python3 -m pipx run --spec qmpass-cli==0.3.0 qmpass-cli gate evaluate --release 10023 --stage PST-02
```

Azure DevOps (secret variable `QMPASS_TOKEN` — secrets must be mapped into `env`; Microsoft-hosted
`ubuntu-latest` has pipx and Docker):

```yaml
- script: |
    pipx install qmpass-cli==0.3.0
    qmpass-cli gate evaluate --release 10023 --stage PST-02
  displayName: Qmpass gate
  env:
    QMPASS_TOKEN: $(QMPASS_TOKEN)
```

Jenkins (declarative; a secret-text credential `qmpass-token`; the agent needs Python 3.10+, pipx and Docker):

```groovy
stage('Qmpass gate') {
  environment {
    QMPASS_TOKEN = credentials('qmpass-token')
  }
  steps {
    sh 'pipx install qmpass-cli==0.3.0'
    sh 'qmpass-cli gate evaluate --release 10023 --stage PST-02'
  }
}
```

No Docker on the runner? Run the Qmpass agent on a machine your team controls and add `--agent <name>`.

The temporary agent runs on your runner, so it reaches whatever the runner reaches (preview
deploys, internal URLs on self-hosted runners). Its token is issued for this evaluation only and
is removed when the evaluation is done with it.

## Report builds and deployments

Tell Qmpass what the pipeline built and where it deployed it. In Qmpass it shows on the release as
**Builds and deployments**: a failed build or deployment is a release risk (or blocks Mark released,
if your project chooses so), and a new build on a stage after its sign-off is flagged.

```bash
qmpass-cli signal push build --component web --status success --version 1.4.0-rc.3
qmpass-cli signal push deployment --environment QA --stage PST-01 --status success --version 1.4.0-rc.3
```

**Which release?** You don't name it. Qmpass matches each push by the **issue keys** in the commits
since the previous push (the CLI reads them with `git log`), the same link Jira uses for branches,
commits and pull requests. A release joins the build or environment when it's next opened in Qmpass and
its stories match — fix versions, sprints and epics alike. Check out with history (`fetch-depth: 0` on
GitHub) so the CLI can read the commits. To pin a push instead, add `--release <id>` — the id at the
end of the release's breadcrumb in Qmpass (`10035`, `sprint-42`, `epic-10051`).

| Option | Default | |
|---|---|---|
| `--status` | required | `running` · `passed` · `failed` for a build; `started` · `succeeded` · `failed` · `rolled_back` for a deployment. Your CI's words work too (`success`, `failure`, `cancelled`, GitHub's `${{ job.status }}`), or `from-exit-code` (Bitbucket `BITBUCKET_EXIT_CODE`, or `QMPASS_EXIT_CODE`). |
| `--component` (build) | the pipeline name | What was built, e.g. `web`, `api`. Each component + branch is tracked on its own. |
| `--environment` (deployment) | required | Your environment's name: `QA`, `Staging`, `Production`. |
| `--stage` (deployment) | | The release stage this environment feeds (`PST-01`): Qmpass then flags a new build there after the stage's sign-off. |
| `--release` | | Pin to this release instead of matching by issue keys. |
| `--issues` | `auto` | `auto` (git log since the previous push), `none`, or keys: `SAM-1,SAM-2`. |
| `--version`, `--commit`, `--branch`, `--build-url` | from the CI environment | Shown in Qmpass. |
| `--strict` | | Fail the step when Qmpass can't be reached. |

Exit codes: `0` pushed — and also when Qmpass can't be reached (a warning; the deploy goes on unless
`--strict`), `3` Qmpass refused the push (bad token, unknown release or stage, invalid status).

GitHub Actions — report the job's result even when it fails:

```yaml
- uses: actions/checkout@v4
  with: { fetch-depth: 0 }
- run: ./deploy.sh qa
- name: Qmpass deployment
  if: always()
  run: |
    pipx install qmpass-cli==0.3.0
    qmpass-cli signal push deployment --environment QA --stage PST-01 --status ${{ job.status }}
  env:
    QMPASS_TOKEN: ${{ secrets.QMPASS_TOKEN }}
```

Bitbucket Pipelines — an `after-script` runs whether the step passed or failed:

```yaml
- step:
    name: Deploy QA
    image: python:3.12
    clone: { depth: full }
    script:
      - ./deploy.sh qa
    after-script:
      - python3 -m pip install pipx
      - python3 -m pipx run --spec qmpass-cli==0.3.0 qmpass-cli signal push deployment --environment QA --stage PST-01 --status from-exit-code
```

GitLab CI (`GIT_DEPTH: 0` for full history; `after_script` runs after a failed deploy too and sees
its `CI_JOB_STATUS`):

```yaml
deploy-qa:
  image: python:3.12
  variables: { GIT_DEPTH: "0" }
  script:
    - ./deploy.sh qa
  after_script:
    - python3 -m pip install pipx
    - python3 -m pipx run --spec qmpass-cli==0.3.0 qmpass-cli signal push deployment --environment QA --stage PST-01 --status "$CI_JOB_STATUS"
```

Azure DevOps and Jenkins work the same way: install the CLI, then `qmpass-cli signal push …` in a step
that runs on success and failure (`condition: always()` / `post { always { … } }`), passing the
result as `--status`.

