Skip to main content

Bitbucket Pipelines Integration

Trigger Agnox test runs from Bitbucket Pipelines and post execution status comments back to pull requests automatically — giving reviewers instant quality feedback without leaving Bitbucket.


Capabilities​

FeatureDescription
Hosted test runsTrigger Agnox to spin up a Docker container and run your tests
PR status commentsExecution results posted as PR comments with pass/fail counts
CI context taggingExecutions are tagged with the repository, PR number, and commit SHA
Smart PR RoutingPush webhook support for AI-driven test folder selection

Prerequisites​

  • An Agnox API key — generate one in Settings → Profile → API Access.
  • Your Agnox Project ID — found in Settings → Run Settings → Execution Defaults.
  • Bitbucket repository variables configured in Repository Settings → Repository Variables.
  • A Bitbucket App Password or OAuth token with pullrequests:write scope (for PR comments).

Step 1 — Add Secrets to Bitbucket​

In Repository Settings → Repository Variables, add the following:

VariableValueSecured
AGNOX_API_KEYYour Agnox API key✅ Yes
AGNOX_PROJECT_IDYour project IDNo
BITBUCKET_TOKENApp Password with pullrequests:write✅ Yes

Step 2 — Trigger a Hosted Run​

Add this step to your bitbucket-pipelines.yml:

image: atlassian/default-image:4

pipelines:
pull-requests:
'**':
- step:
name: Trigger Agnox E2E Tests
script:
- |
RESPONSE=$(curl -s -X POST https://api.agnox.dev/api/ci/trigger \
-H "Content-Type: application/json" \
-H "x-api-key: $AGNOX_API_KEY" \
-d '{
"projectId": "'"$AGNOX_PROJECT_ID"'",
"image": "your-dockerhub-user/my-tests:latest",
"command": "npx playwright test",
"folder": "tests/e2e",
"config": {
"environment": "staging",
"baseUrl": "https://staging.yourapp.com"
},
"ciContext": {
"source": "webhook",
"repository": "'"$BITBUCKET_REPO_FULL_NAME"'",
"prNumber": '"${BITBUCKET_PR_ID:-0}"',
"commitSha": "'"$BITBUCKET_COMMIT"'"
}
}')
echo "Agnox response: $RESPONSE"
echo "$RESPONSE" > agnox_response.json
artifacts:
- agnox_response.json

By default the run is recorded under Executions only and the response is { taskId, status: "PENDING" }. Add "createCycle": true to also create a Test Cycle for the run (the response then includes cycleId), or "cycleId": "<existing cycle id>" to add the run to an existing cycle in the same project.


Step 3 — Post Results as a PR Comment​

Add a second step that polls for the result and posts it to the PR:

- step:
name: Post Agnox Results to PR
script:
- TASK_ID=$(cat agnox_response.json | python3 -c "import sys,json; print(json.load(sys.stdin)['taskId'])")
- |
# Poll until the execution is no longer PENDING/RUNNING (max 10 min)
for i in $(seq 1 20); do
STATUS=$(curl -s "https://api.agnox.dev/api/executions/$TASK_ID/status" \
-H "x-api-key: $AGNOX_API_KEY" | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['status'])")
echo "Status: $STATUS"
[ "$STATUS" = "RUNNING" ] || [ "$STATUS" = "PENDING" ] || break
sleep 30
done
- |
curl -s -X POST \
"https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_FULL_NAME/pullrequests/$BITBUCKET_PR_ID/comments" \
-u "$BITBUCKET_USERNAME:$BITBUCKET_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\": {\"raw\": \"**Agnox E2E:** $STATUS — [View results](https://app.agnox.dev/executions/$TASK_ID)\"}}"

:::tip Keep pipelines fast If your test suite takes longer than 10 minutes, increase the poll count or switch to a Webhook callback pattern to avoid blocking the pipeline step. :::


Step 4 — Enable PR Routing (Optional)​

To use AI-driven test folder selection based on changed files:

  1. Enable Smart PR Routing in Settings → Features.
  2. Copy the webhook URL shown in Settings → Run Settings, and generate a Webhook Secret there.
  3. Bitbucket webhook payloads do not list changed files, so add a Pipelines step that posts changedFiles to the webhook URL, with the secret in the X-Agnox-Webhook-Token header.

See Smart PR Routing → Bitbucket Setup for the pipeline step and full details.


CI Context Fields​

FieldBitbucket Variable
repository$BITBUCKET_REPO_FULL_NAME
prNumber$BITBUCKET_PR_ID
commitSha$BITBUCKET_COMMIT
branch$BITBUCKET_BRANCH

Troubleshooting​

ErrorLikely Cause
401 Unauthorized from AgnoxAGNOX_API_KEY is wrong or not secured in repo variables
PR comment not postedBITBUCKET_TOKEN is missing pullrequests:write scope
Execution stuck in PENDINGWorker capacity may be at limit — check System Monitor