Skip to content

Jenkins Integration

Jenkins shared library

GOVERN provides a Jenkins shared library. Add it in Manage Jenkins → Configure System → Global Pipeline Libraries:

Name: govern
Default version: main
Retrieval method: Modern SCM
Repository URL: https://github.com/archetypal-ai/govern-jenkins-library

Declarative pipeline

// Jenkinsfile
@Library('govern') _
pipeline {
agent any
environment {
GOVERN_API_KEY = credentials('govern-api-key')
GOVERN_ORG_ID = credentials('govern-org-id')
}
stages {
stage('Test') {
steps {
sh 'npm ci && npm test'
}
}
stage('GOVERN') {
steps {
governAssess(
model: 'claude-sonnet-4-20250514',
testPrompts: 'tests/govern/prompts.json',
failOn: 'flag',
outputFormat: 'junit'
)
}
post {
always {
junit 'govern-results.xml'
}
}
}
stage('Deploy') {
when {
branch 'main'
expression { currentBuild.result == 'SUCCESS' }
}
steps {
sh './deploy.sh'
}
}
}
}

Scripted pipeline

// Jenkinsfile (scripted)
node {
checkout scm
withCredentials([
string(credentialsId: 'govern-api-key', variable: 'GOVERN_API_KEY'),
string(credentialsId: 'govern-org-id', variable: 'GOVERN_ORG_ID')
]) {
stage('GOVERN Assessment') {
sh """
govern assess \\
--batch-file tests/govern/prompts.json \\
--model claude-sonnet-4-20250514 \\
--fail-on-flag \\
--output json > govern-results.json
"""
archiveArtifacts artifacts: 'govern-results.json'
}
}
}

Installing the CLI in Jenkins

stage('Setup') {
steps {
sh 'npm install -g @archetypal-ai/govern-cli'
sh 'govern --version'
}
}

Or use the Docker agent:

pipeline {
agent {
docker {
image 'archetypal/govern-cli:latest'
}
}
stages {
stage('GOVERN') {
steps {
sh 'govern assess --batch-file tests/govern/prompts.json ...'
}
}
}
}

Credentials setup

  1. Navigate to Manage Jenkins → Credentials → System → Global credentials
  2. Add credential → Secret text
  3. ID: govern-api-key, Secret: gvn_live_xxxx
  4. Repeat for govern-org-id

Never put API keys in Jenkinsfiles. Always use Jenkins credentials binding.