Jenkins
Jenkins is a widely-used open-source automation server. With Gaffer, you can automatically upload and share test reports from your Jenkins pipelines.
Prerequisites
Section titled “Prerequisites”- A Gaffer account with a project
- Your project’s upload token
- A Jenkins instance with a pipeline configured
1. Add your upload token as a credential
Section titled “1. Add your upload token as a credential”- Go to Manage Jenkins → Credentials
- Select the appropriate domain (or global)
- Click Add Credentials
- Kind: Secret text
- Secret: Your Gaffer project upload token
- ID:
gaffer-upload-token - Description:
Gaffer Upload Token
2. Add the upload step to your Jenkinsfile
Section titled “2. Add the upload step to your Jenkinsfile”pipeline { agent any
environment { GAFFER_UPLOAD_TOKEN = credentials('gaffer-upload-token') }
stages { stage('Test') { steps { sh 'npm ci' sh 'npm test' } post { always { sh ''' curl -X POST https://app.gaffer.sh/api/upload \ -H "X-API-Key: $GAFFER_UPLOAD_TOKEN" \ -F "files=@test-results/junit.xml" \ -F 'tags={"commitSha":"'"$GIT_COMMIT"'","branch":"'"$GIT_BRANCH"'"}' ''' junit 'test-results/junit.xml' } } } }}Environment Variables
Section titled “Environment Variables”Jenkins provides these variables for your pipeline:
| Variable | Description | Example |
|---|---|---|
$GIT_COMMIT | Full commit SHA | abc123def456... |
$GIT_BRANCH | Branch name (may include origin/) | origin/main, origin/feature/login |
$BRANCH_NAME | Branch name (multibranch pipelines) | main, feature/login |
$BUILD_NUMBER | Build number | 123 |
$JOB_NAME | Job name | my-app/main |
Examples
Section titled “Examples”Playwright
Section titled “Playwright”pipeline { agent { docker { image 'mcr.microsoft.com/playwright:v1.40.0-jammy' } }
environment { GAFFER_UPLOAD_TOKEN = credentials('gaffer-upload-token') }
stages { stage('Install') { steps { sh 'npm ci' } } stage('Test') { steps { sh 'npx playwright test' } post { always { sh ''' curl -X POST https://app.gaffer.sh/api/upload \ -H "X-API-Key: $GAFFER_UPLOAD_TOKEN" \ -F "files=@playwright-report/index.html" \ -F 'tags={"commitSha":"'"$GIT_COMMIT"'","branch":"'"$BRANCH_NAME"'","test_framework":"playwright","test_suite":"e2e"}' ''' archiveArtifacts artifacts: 'playwright-report/**' } } } }}Jest with JUnit Reporter
Section titled “Jest with JUnit Reporter”pipeline { agent any
environment { GAFFER_UPLOAD_TOKEN = credentials('gaffer-upload-token') }
stages { stage('Test') { steps { sh 'npm ci' sh 'npm test -- --reporters=default --reporters=jest-junit' } post { always { sh ''' curl -X POST https://app.gaffer.sh/api/upload \ -H "X-API-Key: $GAFFER_UPLOAD_TOKEN" \ -F "files=@junit.xml" \ -F 'tags={"commitSha":"'"$GIT_COMMIT"'","branch":"'"$BRANCH_NAME"'","test_framework":"jest"}' ''' junit 'junit.xml' } } } }}Declarative with Scripted Post
Section titled “Declarative with Scripted Post”pipeline { agent any
stages { stage('Test') { steps { sh 'npm ci && npm test' } } }
post { always { withCredentials([string(credentialsId: 'gaffer-upload-token', variable: 'GAFFER_UPLOAD_TOKEN')]) { sh ''' # Clean branch name (remove origin/ prefix) CLEAN_BRANCH="${GIT_BRANCH#origin/}"
curl -X POST https://app.gaffer.sh/api/upload \ -H "X-API-Key: $GAFFER_UPLOAD_TOKEN" \ -F "files=@test-results/junit.xml" \ -F 'tags={"commitSha":"'"$GIT_COMMIT"'","branch":"'"$CLEAN_BRANCH"'"}' ''' } } }}Using CTRF Format
Section titled “Using CTRF Format”For a standardized format across all your test frameworks, consider using CTRF:
stage('Test') { steps { // Install the CTRF reporter for your framework: // npm install --save-dev jest-ctrf-json-reporter // npm install --save-dev playwright-ctrf-json-reporter // npm install --save-dev vitest-ctrf-json-reporter sh 'npm install --save-dev jest-ctrf-json-reporter' sh 'npm test -- --reporter=jest-ctrf-json-reporter' } post { always { sh ''' curl -X POST https://app.gaffer.sh/api/upload \ -H "X-API-Key: $GAFFER_UPLOAD_TOKEN" \ -F "files=@ctrf-report.json" \ -F 'tags={"commitSha":"'"$GIT_COMMIT"'","branch":"'"$BRANCH_NAME"'"}' ''' } }}Troubleshooting
Section titled “Troubleshooting”Report not uploading
Section titled “Report not uploading”- Verify the credential ID matches (
gaffer-upload-token) - Ensure the upload is in a
post { always { } }block - Check the file path is correct relative to the workspace
401 Unauthorized
Section titled “401 Unauthorized”- Check your upload token starts with
gfr_ - Verify the credential is accessible to the pipeline
Branch name includes “origin/”
Section titled “Branch name includes “origin/””Use ${GIT_BRANCH#origin/} to strip the prefix:
sh ''' CLEAN_BRANCH="${GIT_BRANCH#origin/}" curl ... -F 'tags={"branch":"'"$CLEAN_BRANCH"'"}''''curl not found
Section titled “curl not found”Ensure curl is installed on your Jenkins agent or use a Docker image that includes it.
Next Steps
Section titled “Next Steps”- CTRF Guide - Use the universal test format
- Upload API Reference - Full API documentation
- Slack Integration - Get test results in Slack
Other CI Providers: GitHub Actions · GitLab CI · CircleCI · Bitbucket · Azure DevOps