Skip to main content

Run Vibgrate in a Jenkins Pipeline

Add a Vibgrate stage to a Jenkins declarative pipeline that scans for drift, archives a SARIF report, and fails the build when a drift budget is exceeded.

Difficulty
Intermediate
Duration
20 minutes
Steps
5

Jenkins declarative pipelines run stages defined in a Jenkinsfile. A Vibgrate stage adds a DriftScore to every build and can fail the build when a drift budget is breached, with the SARIF report archived for later review.

Prerequisites

  • A Jenkins controller with an agent that has Node.js installed.
  • A Jenkinsfile checked into the repository.

Steps

1. Add a stage to the Jenkinsfile

Declare a stage inside the pipeline block.

pipeline {
  agent any
  stages {
    stage('Vibgrate Drift') {
      steps {
      }
    }
  }
}

2. Run the scan in the stage

Call the CLI with the no-install form inside an sh step.

        sh 'npx @vibgrate/cli scan'

The console output shows the DriftScore and the findings that contributed to it.

3. Archive the SARIF report

Produce SARIF and archive it as a build artifact.

        sh 'npx @vibgrate/cli scan --format sarif --out vibgrate.sarif'
        archiveArtifacts artifacts: 'vibgrate.sarif'

4. Fail the build on budget

Apply a drift budget. A non-zero exit code from the sh step fails the stage and the build.

        sh 'npx @vibgrate/cli scan --drift-budget 60'

5. Verify the build

Trigger a build and open the console log. The Vibgrate stage should print a DriftScore, and the archived SARIF should appear on the build page.

Verification

A scan within budget exits 0 and the stage passes. A breach exits non-zero, which Jenkins treats as a failed stage. Check the archived artifacts list for vibgrate.sarif.

vg scan --drift-budget 60

Next Steps

  • Add a scheduled trigger for nightly drift scans.
  • Limit scope on PR-style builds with vg scan --changed-only.
  • Push results to Vibgrate Cloud with vg scan --push.

Prerequisites

  • A Jenkins controller and agent
  • Node.js available on the agent
  • A Jenkinsfile in the repo

Steps

  • 1
    Add a stage to the Jenkinsfile
  • 2
    Run the scan in the stage
  • 3
    Archive the SARIF report
  • 4
    Fail the build on budget
  • 5
    Verify the build

Category

Vibgrate