Skip to content

Send results from CI

Open CI integration in the project. Select the test run and download ztm for Windows or Linux (x64). Put it on your trusted runner’s executable search path. On Linux, first make it executable with chmod +x ztm.

  1. Set ZTM_BASE_URL to your server address, ZTM_PROJECT_UNIQUE_ID to the project GUID, and ZTM_API_KEY in your pipeline’s secret store. Include the application path in the base URL if your deployment uses one.
  2. Run ztm runs list and note an open run ID.
  3. Start with a preview. It lists external case IDs, eligible planned variants in Targets, and project definitions in ResultDefinitions.

    ztm results upload --run 4711 --file "results/**/*.xml" --dry-run --json
    
  4. Review the targets and store the mappings in ztm-mappings.json. Each entry needs an externalCaseId and plannedVariantId. If the project offers multiple success or failure definitions, set successResultDefinitionId or failureResultDefinitionId. A single resultDefinitionId applies to both modes and is suitable only for a deliberately fixed outcome.

  5. Import the report. The receipt separates imported, already imported, skipped, and unmapped results. Check the run after importing.

    ztm results upload --run 4711 --file "results/**/*.xml" --source CI --build-id 1082 --fail-on-unmapped
    

Repeat --file to supply several patterns. --format auto detects JUnit, NUnit 3, and TRX. --mappings selects another file. --url and --project override the environment variables. --timeout applies per REST call. Use ztm help for all options and ztm version to verify the executable.

Pipeline examples

The snippets expect existing reports and the ztm executable on the runner. Configure the variables from step 1 and set ZTM_TEST_RUN_ID to the run ID. Expose the key only to trusted jobs.

GitHub Actions

# Merge this job into your trusted pipeline after reports have been generated.
name: Send test results to ZTM
on:
  workflow_dispatch:
jobs:
  upload:
    runs-on: [self-hosted, linux, x64, ztm]
    steps:
      - uses: actions/checkout@v4
      # Insert your existing report producer or artifact download step here.
      - name: Import automated results
        env:
          ZTM_API_KEY: ${{ secrets.ZTM_API_KEY }}
          ZTM_BASE_URL: ${{ vars.ZTM_BASE_URL }}
          ZTM_PROJECT_UNIQUE_ID: ${{ vars.ZTM_PROJECT_UNIQUE_ID }}
          ZTM_TEST_RUN_ID: ${{ vars.ZTM_TEST_RUN_ID }}
        run: ztm results upload --run "$ZTM_TEST_RUN_ID" --file 'results/**/*.xml' --source GitHub-Actions --build-id "$GITHUB_RUN_ID" --fail-on-unmapped

GitLab CI

# Merge this job after the job that supplies results/ as an artifact.
ztm-upload:
  stage: deploy
  tags: [ztm-linux-x64]
  rules:
    - if: '$CI_COMMIT_REF_PROTECTED == "true"'
  script:
    - ztm results upload --run "$ZTM_TEST_RUN_ID" --file 'results/**/*.xml' --source GitLab --build-id "$CI_PIPELINE_ID" --fail-on-unmapped

Azure Pipelines

# Merge this step after your existing report-producing steps.
steps:
  - bash: ztm results upload --run "$ZTM_TEST_RUN_ID" --file 'results/**/*.xml' --source Azure-Pipelines --build-id "$BUILD_BUILDID" --fail-on-unmapped
    displayName: Import automated results
    env:
      ZTM_API_KEY: $(ZTM_API_KEY)
      ZTM_BASE_URL: $(ZTM_BASE_URL)
      ZTM_PROJECT_UNIQUE_ID: $(ZTM_PROJECT_UNIQUE_ID)
      ZTM_TEST_RUN_ID: $(ZTM_TEST_RUN_ID)

Jenkins

pipeline {
    agent { label 'ztm-linux-x64' }
    stages {
        // Add your existing test stage before this upload stage.
        stage('Import automated results') {
            steps {
                withCredentials([string(credentialsId: 'ztm-project-api-key', variable: 'ZTM_API_KEY')]) {
                    sh 'ztm results upload --run "$ZTM_TEST_RUN_ID" --file "results/**/*.xml" --source Jenkins --build-id "$BUILD_TAG" --fail-on-unmapped'
                }
            }
        }
    }
}

Permissions, limits, and retries

The project API key needs read and preview access plus project.automation-import.commit. Listing runs needs project.knowledge.query. The associated project user must be able to edit the run and read the target variants. Enable MCP and project writes. A preview changes no test results. Plain HTTP is for loopback testing only. You can also provide the key on the first line of standard input.

The tool splits large reports into batches of at most 1,000 cases. Each individual result and its required metadata must fit one REST request. Existing results are protected. Earlier batches may be saved if the connection fails. Review the receipt and import history before retrying with the same reports, mappings, run, and build ID.

Code Meaning
0 Import or preview succeeded
1 Authentication, transfer, or import failed
2 --fail-on-unmapped found unmapped results
3 Invalid command line or input file