Overview
Integrating Metlo tests into your CI/CD pipeline helps you:- Catch security vulnerabilities before they reach production
- Automate security testing as part of your deployment process
- Fail builds when critical security issues are detected
- Track security test results over time
Prerequisites
GitHub Actions
Basic Workflow
Create.github/workflows/security-tests.yml:
With Test Results Artifact
Capture test results for later review:Multi-Environment Testing
Test against multiple environments:GitLab CI
Basic Pipeline
Create.gitlab-ci.yml:
With Test Reports
Environment-Specific Tests
Jenkins
Declarative Pipeline
CreateJenkinsfile:
With Parallel Execution
CircleCI
Basic Configuration
Create.circleci/config.yml:
Azure Pipelines
Pipeline Configuration
Createazure-pipelines.yml:
Docker-Based Testing
Run tests in a Docker container:Dockerfile
Docker Compose
Environment Variable Management
Best Practices
Run tests on every pull request
Run tests on every pull request
Catch security issues before they’re merged:
Use separate environments
Use separate environments
Test against staging or dedicated test environments, not production:
Store sensitive data in CI secrets
Store sensitive data in CI secrets
Never commit credentials to your repository:
- GitHub: Repository Settings → Secrets
- GitLab: Settings → CI/CD → Variables
- Jenkins: Credentials plugin
- CircleCI: Project Settings → Environment Variables
Fail fast on critical issues
Fail fast on critical issues
Set exit codes to fail the build:
Run subsets of tests at different stages
Run subsets of tests at different stages
- PR: Quick smoke tests
- Merge to develop: Full test suite
- Production deployment: Critical tests only
Archive test results
Archive test results
Save test output for debugging:
Set up notifications
Set up notifications
Alert your team when tests fail:
- Slack notifications
- Email alerts
- GitHub PR comments
Troubleshooting
Tests pass locally but fail in CI
Tests pass locally but fail in CI
Common causes:
- Different environment variables
- Network access restrictions
- Timing issues (add delays if needed)
- Different Node.js versions
- Verify environment variables are set
- Check CI environment can reach your API
- Pin Node.js version in CI config
Tests timeout in CI
Tests timeout in CI
CI environments may have stricter timeouts:
Rate limiting issues
Rate limiting issues
Space out test execution:
Next Steps
Writing Tests
Learn how to write comprehensive security tests
Custom Templates
Create custom test templates for your needs