Jenkins · CI/CD · DevSecOps · SonarQube · Snyk · Playwright · GitHub Actions

A Jenkins pipeline that blocks insecure code: Snyk, SonarQube, and Playwright gates

By Naufal Randi Aldiansyah · · 2 min read

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

Three rules that keep gates alive

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.com

The 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.