A Jenkins pipeline that blocks insecure code: Snyk, SonarQube, and Playwright gates
At Hashmicro I ran release pipelines for enterprise ERP platforms on Jenkins with SonarQube analysis and Playwright verification. Before that, at Media Telekomunikasi Mandiri, the same idea ran on GitHub Actions with Snyk. One rule makes it work: a gate is a stage that can fail the build. A scan that only produces a report is not a gate.
The pipeline
pipeline {
agent any
options { timeout(time: 30, unit: 'MINUTES') }
stages {
stage('Test') {
steps { sh 'npm ci && npm test' }
}
stage('Dependency scan') {
steps {
withCredentials([string(credentialsId: 'snyk-token', variable: 'SNYK_TOKEN')]) {
sh 'npx snyk test --severity-threshold=high'
}
}
}
stage('Static analysis') {
steps {
withSonarQubeEnv('sonarqube') { sh 'npx sonar-scanner' }
timeout(time: 10, unit: 'MINUTES') { waitForQualityGate abortPipeline: true }
}
}
stage('Deploy to staging') {
steps { sh './deploy.sh staging' }
}
stage('Verify release') {
steps { sh 'BASE_URL=https://staging.example.com npx playwright test --grep @smoke' }
post { always { archiveArtifacts artifacts: 'playwright-report/**', allowEmptyArchive: true } }
}
stage('Deploy to production') {
when { branch 'main' }
steps { sh './deploy.sh production' }
}
}
}Why each gate is there
- Dependency scan runs early because it is cheap and catches known vulnerabilities in packages you did not write.
--severity-threshold=highstops the build for high and critical issues only, so the gate does not fail on noise. - Static analysis becomes binding through
waitForQualityGate abortPipeline: true. It needs a webhook in SonarQube that points to/sonarqube-webhook/on Jenkins. Without it the step waits until the timeout. - Release verification runs a Playwright smoke suite against staging after the deploy: sign in, complete one critical transaction, sign out. It tests the thing that was deployed, not the thing that was built.
Three rules that keep gates alive
- Gate on new code. Set the SonarQube quality gate to judge new code, or an old codebase fails every build and the team switches the gate off.
- Every exception has an owner and an expiry date. In Snyk, use an ignore entry with
expiresand a reason, never a blanket skip. - Keep the pipeline under about fifteen minutes. Run the scans in parallel if needed. People route around slow gates.
The same gates in GitHub Actions
jobs:
gates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 22, cache: npm }
- run: npm ci && npm test
- run: npx snyk test --severity-threshold=high
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
- run: npx playwright install --with-deps chromium
- run: npx playwright test --grep @smoke
env:
BASE_URL: https://staging.example.comThe tool matters less than the rule. Each step exits non-zero on a finding, and the branch protection requires the job to pass before a merge.