Skip to main content

Bitbucket Pipelines Integration with TestCollab for CI/CD pipelines

Step-by-step guide to uploading automated test results from Bitbucket Pipelines to TestCollab using @testcollab/cli.

Updated today

This guide walks you through setting up a Bitbucket Pipeline that automatically creates a test plan in TestCollab, runs your tests, and uploads the results — all using the TestCollab CLI.

Prerequisites

  1. A TestCollab API token (from Account Settings → API Tokens)

  2. Your TestCollab project ID

  3. A tag applied to the test cases you want to run in CI (note the tag ID)

  4. The assignee user ID for pipeline executions

  5. Test case IDs embedded in your test names (e.g., [TC-42] Login should succeed)

Step 1: Add Repository Variables

Go to your Bitbucket repository → Repository settings → Pipelines → Repository variables and add the following variables. Mark TESTCOLLAB_TOKEN as Secured to keep it hidden in logs.

Variable Name

Value

Secured

TESTCOLLAB_TOKEN

Your TestCollab API token

Yes

TC_PROJECT_ID

Your TestCollab project ID (number)

No

TC_CI_TAG_ID

Tag ID for CI test cases (number)

No

TC_ASSIGNEE_ID

Assignee user ID (number)

No

Step 2: Create the Pipeline Configuration

Create a bitbucket-pipelines.yml file in the root of your repository. Below are complete examples for common test frameworks.

Example: Playwright (JUnit XML)

image: node:22
pipelines:
  default:
    - step:
        name: Run Tests & Upload to TestCollab
        caches:
          - node
        script:
          - npm ci
          - npm install -g @testcollab/cli
          - npx playwright install --with-deps chromium
          - tc createTestPlan --project $TC_PROJECT_ID --ci-tag-id $TC_CI_TAG_ID --assignee-id $TC_ASSIGNEE_ID
          - source tmp/tc_test_plan
          - PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --reporter=junit || true
          - tc report --project $TC_PROJECT_ID --test-plan-id $TESTCOLLAB_TEST_PLAN_ID --format junit --result-file ./results.xml

Example: Cypress (Mochawesome JSON)

image: cypress/included:latest
pipelines:
  default:
    - step:
        name: Run Tests & Upload to TestCollab
        caches:
          - node
        script:
          - npm ci
          - npm install -g @testcollab/cli
          - tc createTestPlan --project $TC_PROJECT_ID --ci-tag-id $TC_CI_TAG_ID --assignee-id $TC_ASSIGNEE_ID
          - source tmp/tc_test_plan
          - npx cypress run --reporter mochawesome --reporter-options reportDir=results,overwrite=false,html=false,json=true || true
          - tc report --project $TC_PROJECT_ID --test-plan-id $TESTCOLLAB_TEST_PLAN_ID --format mochawesome --result-file ./results/mochawesome.json

Example: pytest (JUnit XML)

image: python:3.12
pipelines:
  default:
    - step:
        name: Run Tests & Upload to TestCollab
        script:
          - pip install -r requirements.txt
          - curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
          - apt-get install -y nodejs
          - npm install -g @testcollab/cli
          - tc createTestPlan --project $TC_PROJECT_ID --ci-tag-id $TC_CI_TAG_ID --assignee-id $TC_ASSIGNEE_ID
          - source tmp/tc_test_plan
          - pytest --junitxml=results.xml || true
          - tc report --project $TC_PROJECT_ID --test-plan-id $TESTCOLLAB_TEST_PLAN_ID --format junit --result-file ./results.xml

Example: Java / Maven (JUnit XML)

image: maven:3.9-eclipse-temurin-21
pipelines:
  default:
    - step:
        name: Run Tests & Upload to TestCollab
        caches:
          - maven
        script:
          - curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
          - apt-get install -y nodejs
          - npm install -g @testcollab/cli
          - tc createTestPlan --project $TC_PROJECT_ID --ci-tag-id $TC_CI_TAG_ID --assignee-id $TC_ASSIGNEE_ID
          - source tmp/tc_test_plan
          - mvn test || true
          - tc report --project $TC_PROJECT_ID --test-plan-id $TESTCOLLAB_TEST_PLAN_ID --format junit --result-file ./target/surefire-reports/TEST-*.xml

How It Works

Each pipeline step follows the same three-step pattern:

  1. Create test plantc createTestPlan creates a new test plan in TestCollab containing all test cases tagged with your CI tag. It writes the plan ID to tmp/tc_test_plan.

  2. Source the plan IDsource tmp/tc_test_plan loads TESTCOLLAB_TEST_PLAN_ID as an environment variable for the rest of the script.

  3. Upload resultstc report parses your test output and updates each test case execution in the plan.

The || true after the test command ensures the pipeline continues to the upload step even when tests fail, so you always get results in TestCollab.

Branch-Specific Pipelines

You can run tests on specific branches instead of every push:

pipelines:
  branches:
    main:
      - step:
          name: Run Tests & Upload to TestCollab
          image: node:22
          script:
            - npm ci
            - npm install -g @testcollab/cli
            - npx playwright install --with-deps chromium
            - tc createTestPlan --project $TC_PROJECT_ID --ci-tag-id $TC_CI_TAG_ID --assignee-id $TC_ASSIGNEE_ID
            - source tmp/tc_test_plan
            - PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --reporter=junit || true
            - tc report --project $TC_PROJECT_ID --test-plan-id $TESTCOLLAB_TEST_PLAN_ID --format junit --result-file ./results.xml
    develop:
      - step:
          name: Run Tests & Upload to TestCollab
          image: node:22
          script:
            - npm ci
            - npm install -g @testcollab/cli
            - npx playwright install --with-deps chromium
            - tc createTestPlan --project $TC_PROJECT_ID --ci-tag-id $TC_CI_TAG_ID --assignee-id $TC_ASSIGNEE_ID
            - source tmp/tc_test_plan
            - PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --reporter=junit || true
            - tc report --project $TC_PROJECT_ID --test-plan-id $TESTCOLLAB_TEST_PLAN_ID --format junit --result-file ./results.xml

Test Case ID Mapping

The CLI matches results to TestCollab test cases by looking for ID patterns in your test names:

  • [TC-42] Login should succeed

  • TC-42 Login should succeed

  • Login should succeed id-42

  • Login should succeed testcase-42

All patterns are case-insensitive. See the main CLI documentation for full details on ID patterns, configuration support, and troubleshooting.

EU Region

If your TestCollab account is on the EU region, add --api-url https://api-eu.testcollab.io to both the tc createTestPlan and tc report commands.

Troubleshooting

Results not uploading

  • Check that TESTCOLLAB_TOKEN is set correctly in repository variables and marked as Secured

  • Verify the result file path matches what your test framework actually outputs

  • Make sure the --format flag matches your output format (junit or mochawesome)

Test cases not matched

  • Ensure your test names include a TestCollab ID pattern (e.g., [TC-42])

  • Verify the test cases are tagged with the CI tag and assigned to the correct user in the test plan

Pipeline fails at npm install

  • If using a non-Node Docker image (e.g., Python, Java), you need to install Node.js first — see the pytest and Maven examples above

  • Alternatively, use a Node base image and install other runtimes as needed

Did this answer your question?