Using Vaktum
CI/CD
Integrating Vaktum with CI/CD Pipelines
Vaktum seamlessly integrates with your continuous integration and continuous deployment (CI/CD) pipelines to ensure your APIs are validated and tested at every stage of your development lifecycle.
Benefits of CI/CD Integration
- Automated Validation: Automatically validate API specifications in every build
- Regression Prevention: Catch breaking changes before they reach production
- Quality Gates: Establish API quality requirements for deployments
- Deployment Confidence: Deploy with confidence knowing your API behaves as expected
- Historical Tracking: Track API quality metrics over time
Common CI/CD Integration Patterns
Pre-Deployment Validation
Run API validation and tests before deploying:
- Validate the API specification
- Run tests against a staging environment
- Block deployment if validation or tests fail
Post-Deployment Verification
Verify deployed APIs are functioning correctly:
- Deploy to the target environment
- Run tests against the newly deployed API
- Roll back if verification tests fail
Continuous Monitoring
Run tests periodically against production:
- Schedule regular test runs against production
- Alert if issues are detected
- Create incidents for investigation
CI/CD Platform Integrations
GitHub Actions
# .github/workflows/api-validation.yml
name: API Validation
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
validate_api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get install -y curl
- name: Download and run vaktum validate
run: |
curl -sSL -o vaktum https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64
chmod +x vaktum
./vaktum validate path/to/openapi.json
test_api_remote:
runs-on: ubuntu-latest
steps:
- name: Call remote test suite
run: |
curl -X POST "https://api.vaktum.com/v1/run-test-suite/{testSuiteId}/environment/{environmentId}" \
-H "X-API-KEY: your-api-key"
test_api_local:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install -y curl
- name: Download and run vaktum test
run: |
curl -sSL -o vaktum https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64
chmod +x vaktum
./vaktum test --tests path/to/tests.json --env path/to/staging-env.json
GitLab CI
# .gitlab-ci.yml
stages:
- validate
- test
validate_api:
stage: validate
image: alpine:latest
before_script:
- apk add --no-cache curl
- curl -sSL -o vaktum "https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64"
- chmod +x vaktum
script:
- ./vaktum validate path/to/openapi.json
test_api_remote:
stage: test
image: alpine:latest
before_script:
- apk add --no-cache curl
script:
- curl -X POST "https://api.vaktum.com/v1/run-test-suite/{testSuiteId}/environment/{environmentId}" -H "X-API-KEY: your-api-key"
test_api_local:
stage: test
image: alpine:latest
before_script:
- apk add --no-cache curl
- curl -sSL -o vaktum "https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64"
- chmod +x vaktum
script:
- ./vaktum test --tests path/to/tests.json --env path/to/staging-env.json
Jenkins Pipeline
// Jenkinsfile
pipeline {
agent any
stages {
stage('Validate API') {
steps {
sh '''
curl -sSL -o vaktum https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64
chmod +x vaktum
./vaktum validate path/to/openapi.json
'''
}
}
stage('Test API Remote') {
steps {
sh '''
curl -X POST "https://api.vaktum.com/v1/run-test-suite/{testSuiteId}/environment/{environmentId}" \
-H "X-API-KEY: your-api-key"
'''
}
}
stage('Test API Local') {
steps {
sh '''
curl -sSL -o vaktum https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64
chmod +x vaktum
./vaktum test --tests path/to/tests.json --env path/to/staging-env.json
'''
}
}
}
}
Azure DevOps
# azure-pipelines.yml
trigger:
- main
pool:
vmImage: ubuntu-latest
stages:
- stage: Validate
jobs:
- job: ValidateAPI
steps:
- script: |
curl -sSL -o vaktum https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64
chmod +x vaktum
./vaktum validate path/to/openapi.json
displayName: Run vaktum validate
- stage: Test
jobs:
- job: TestRemote
steps:
- script: |
curl -X POST "https://api.vaktum.com/v1/run-test-suite/{testSuiteId}/environment/{environmentId}" \
-H "X-API-KEY: your-api-key"
displayName: Call remote test suite
- job: TestLocal
steps:
- script: |
curl -sSL -o vaktum https://storage.googleapis.com/vaktum_binaries/releases/vaktum-v1.0.4-linux-amd64
chmod +x vaktum
./vaktum test --tests path/to/tests.json --env path/to/staging-env.json
displayName: Run vaktum test
Authentication in CI/CD
Secure ways to authenticate with Vaktum in CI/CD:
- Environment Variables: Store API keys as secure environment variables
vaktum test --tests tests.json --env env.json --api-key $VAKTUM_API_KEY
- Secrets Management: Use your CI/CD platform's secrets management
# GitHub Actions example - name: Run Tests run: vaktum test --tests tests.json --env env.json --api-key ${{ secrets.VAKTUM_API_KEY }}
- CI-Specific Tokens: Create dedicated API tokens for CI/CD use with limited permissions
Advanced CI/CD Scenarios
Multi-Environment Testing
Test against multiple environments in sequence:
# Test development environment
vaktum test --tests tests.json --env dev-env.json
# Test staging environment
vaktum test --tests tests.json --env staging-env.json
# Test production environment (if tests are safe for production)
vaktum test --tests tests.json --env prod-env.json
Test Selection
Run specific tests based on changes:
# Run tests affected by changes in this commit
vaktum test --tests tests.json --env env.json --tags "$(git diff --name-only HEAD~1 | grep -oP 'api/\K[^/]+')"
Reporting and Metrics
Generate test reports for CI/CD dashboards:
# Generate JUnit-compatible XML report
vaktum test --tests tests.json --env env.json --report-format junit --report-output test-results.xml
CI/CD Best Practices
- Fail Fast: Run validation early in the pipeline to catch issues quickly
- Idempotent Tests: Ensure tests can run multiple times without side effects
- Environment Isolation: Use isolated environments for testing
- Parallelization: Run tests in parallel for faster feedback
- Retry Logic: Implement intelligent retry for transient failures
- Notifications: Configure notifications for test failures
For information on long-running jobs and scheduled testing, see Long Running Jobs.