CI/CD Integration
Integrate PostQode CLI into your CI/CD pipelines to automate API testing and generate reports as part of your development workflow. This ensures consistent API quality and catches issues early in the development cycle.
🎯 Overview​
PostQode CLI is designed for seamless CI/CD integration with:
- Exit codes that indicate test success/failure
- JUnit XML reports for test result integration
- Flexible configuration for different environments
- Artifact generation for report archiving
- Parallel execution support
🚀 Quick Start​
Basic CI/CD Command​
postqode execute \
-s testSuites/APITests/_meta.suite.yaml \
--report-formats junit \
--report-dir ./test-results
Exit Codes​
0- All tests passed1- One or more tests failed2- CLI execution error
🔧 Platform-Specific Integration​
GitHub Actions​
Create .github/workflows/api-tests.yml:
name: API Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
api-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install PostQode CLI
run: npm install -g @postqode/cli
- name: Run API Tests
run: |
postqode execute \
-s testSuites/APITests/_meta.suite.yaml \
--report-formats junit html \
--report-dir ./test-results
- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: API Test Results
path: 'test-results/postqode-junit-*.xml'
reporter: java-junit
- name: Upload HTML Reports
uses: actions/upload-artifact@v4
if: always()
with:
name: api-test-reports
path: test-results/
Jenkins Pipeline​
Create Jenkinsfile:
pipeline {
agent any
environment {
NODE_VERSION = '18'
}
stages {
stage('Setup') {
steps {
// Install Node.js and PostQode CLI
sh '''
curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g @postqode/cli
'''
}
}
stage('API Tests') {
steps {
sh '''
postqode execute \
-s testSuites/RegressionTests/_meta.suite.yaml \
--report-formats junit html \
--report-dir ./test-results
'''
}
post {
always {
// Publish JUnit results
junit 'test-results/postqode-junit-*.xml'
// Archive HTML reports
archiveArtifacts artifacts: 'test-results/*.html', fingerprint: true
// Publish HTML reports
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'test-results',
reportFiles: 'postqode-report-*.html',
reportName: 'API Test Report'
])
}
}
}
}
post {
failure {
emailext (
subject: "API Tests Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER}",
body: "API tests have failed. Check the build at ${env.BUILD_URL}",
to: "${env.CHANGE_AUTHOR_EMAIL}"
)
}
}
}
GitLab CI​
Create .gitlab-ci.yml:
stages:
- test
- report
variables:
NODE_VERSION: "18"
before_script:
- apt-get update -qq && apt-get install -y -qq curl
- curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash -
- apt-get install -y nodejs
- npm install -g @postqode/cli
api_tests:
stage: test
script:
- postqode execute -s testSuites/APITests/_meta.suite.yaml --report-formats junit html --report-dir ./test-results
artifacts:
when: always
reports:
junit: test-results/postqode-junit-*.xml
paths:
- test-results/
expire_in: 1 week
coverage: '/Coverage: \d+\.\d+%/'
pages:
stage: report
dependencies:
- api_tests
script:
- mkdir public
- cp test-results/*.html public/ || true
artifacts:
paths:
- public
only:
- main
Azure DevOps​
Create azure-pipelines.yml:
trigger:
branches:
include:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
variables:
nodeVersion: '18.x'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(nodeVersion)
displayName: 'Install Node.js'
- script: |
npm install -g @postqode/cli
displayName: 'Install PostQode CLI'
- script: |
postqode execute \
-s testSuites/APITests/_meta.suite.yaml \
--report-formats junit html \
--report-dir $(Agent.TempDirectory)/test-results
displayName: 'Run API Tests'
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(Agent.TempDirectory)/test-results/postqode-junit-*.xml'
testRunTitle: 'API Tests'
- task: PublishHtmlReport@1
condition: always()
inputs:
reportDir: '$(Agent.TempDirectory)/test-results'
tabName: 'API Test Report'
🔧 Advanced Configuration​
Environment-Specific Testing​
Multiple Environments​
# GitHub Actions example
strategy:
matrix:
environment: [dev, staging, prod]
steps:
- name: Run Tests - ${{ matrix.environment }}
run: |
postqode execute \
-s testSuites/APITests/_meta.suite.yaml \
-c ${{ matrix.environment }} \
--report-formats junit \
--report-dir ./test-results-${{ matrix.environment }}
Environment Variables​
# Set environment-specific variables
export API_BASE_URL=https://api-staging.example.com
export API_KEY=${{ secrets.STAGING_API_KEY }}
postqode execute \
-s testSuites/APITests/_meta.suite.yaml \
--report-formats junit html \
--report-dir ./test-results
Parallel Test Execution​
Multiple Test Suites​
# GitHub Actions parallel jobs
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Run Unit Tests
run: postqode execute -s testSuites/UnitTests/_meta.suite.yaml
integration-tests:
runs-on: ubuntu-latest
steps:
- name: Run Integration Tests
run: postqode execute -s testSuites/IntegrationTests/_meta.suite.yaml
e2e-tests:
runs-on: ubuntu-latest
steps:
- name: Run E2E Tests
run: postqode execute -s testSuites/E2ETests/_meta.suite.yaml
Conditional Execution​
Branch-Based Testing​
# Different tests for different branches
- name: Run Smoke Tests
if: github.ref == 'refs/heads/main'
run: postqode execute -s testSuites/SmokeTests/_meta.suite.yaml
- name: Run Full Regression
if: github.ref == 'refs/heads/develop'
run: postqode execute -s testSuites/RegressionTests/_meta.suite.yaml
Pull Request Testing​
# Only run on pull requests
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
pr-tests:
runs-on: ubuntu-latest
steps:
- name: Run PR Tests
run: postqode execute -s testSuites/PRTests/_meta.suite.yaml
📊 Report Integration​
Test Result Dashboards​
Jenkins Dashboard​
// In Jenkinsfile
post {
always {
// Publish test results for trending
junit 'test-results/postqode-junit-*.xml'
// Create test result trend
step([$class: 'Publisher', reportFilenamePattern: 'test-results/postqode-junit-*.xml'])
}
}
GitHub Actions Summary​
- name: Test Summary
uses: test-summary/action@v2
with:
paths: "test-results/postqode-junit-*.xml"
if: always()
Notification Integration​
Slack Notifications​
# GitHub Actions
- name: Slack Notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
text: 'API Tests completed with status: ${{ job.status }}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
if: always()
Email Notifications​
// Jenkins
post {
failure {
emailext (
subject: "API Tests Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER}",
body: """
API tests have failed in build ${env.BUILD_NUMBER}.
Check the results at: ${env.BUILD_URL}
Test Report: ${env.BUILD_URL}API_Test_Report/
""",
to: "${env.CHANGE_AUTHOR_EMAIL}"
)
}
}
📚 Best Practices​
Pipeline Design​
- Fail fast - Run quick smoke tests first
- Parallel execution - Run independent test suites in parallel
- Environment isolation - Use separate environments for different branches
- Artifact management - Archive reports and logs
Test Organization​
- Separate test suites by functionality or speed
- Use descriptive names for test suites and cases
- Tag tests for selective execution
- Maintain test data independence
Reporting Strategy​
- Always generate JUnit for CI/CD integration
- Include HTML reports for manual review
- Archive reports for historical analysis
- Set up notifications for failures
Security Considerations​
- Use secrets for API keys and credentials
- Avoid hardcoding sensitive information
- Rotate credentials regularly
- Limit access to test environments
🔗 Related Topics​
- Report Formats - Learn about available report formats
- HTML Report Generation - Detailed HTML reporting
- PostQode CLI - Main CLI documentation
- Test Suite Management - Organize your test suites