Use deployment gating with Jenkins
Changes to Jira Service Management Free and Standard
As of October 16, 2024, change management in Jira Service Management has moved from Standard to Premium. Existing service projects in Free and Standard will continue to support existing request types and work types. Read more about the plan changes.
To access Jira Service Management Premium features, subscribe to a Service Collection Premium or Enterprise plan.
Use deployment gating to create a change request with an approval gate at any stage in your Jenkins pipeline. Control if (and when) the pipeline should continue using statuses in the change request Jira workflow. Stakeholders can allow or prevent the deployment from Jira Service Management.
Before you can use deployment gating, you’ll need to:
To use deployment gating with Jenkins:
Go to your Jenkinsfile.
Find the stage in the pipeline where you would like to raise a change request. For example, before the ‘Production’ deployment stage.
We recommend adding 2 stages to your pipeline for deployment gating: One stage to raise a change request, and another stage to check the status of the change request.
Add the following snippet to your pipeline, replacing your Jira site name, environment ID, environment type and service ID(s) you copied from your Jira Service Management project.
stage('Request approval') { // Raise change request
steps {
echo 'Raise change request...'
jiraSendDeploymentInfo(site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1',
environmentName:'us-prod-1',
environmentType:'production',
state:"pending",
enableGating:true,
serviceIds: [
'<YOUR-SERVICE-ID>'
]
)
}
}
stage("Approval gate") { // Check request status
steps {
retry(20) { // Poll every 30s for 10min
waitUntil {
sleep 30
checkGatingStatus(
site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1'
)
}
}
}
}
Snippet example: Raise gated change request
stage('Request approval') { // Raise change request
steps {
echo 'Raise change request...'
jiraSendDeploymentInfo(site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1',
environmentName:'us-prod-1',
environmentType:'production',
state:"pending", // Deployment has not started yet
enableGating:true, // Notify Jira the pipeline is gated
serviceIds: [
'<YOUR-SERVICE-ID>'
]
)
}
}
Snippet example: Manually check change request status
stage("Approval gate") {
steps {
waitUntil {
input message: "Check for approval?" // Manually trigger check status
checkGatingStatus(
site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1'
)
}
}
}
}
Snippet example: Automatically check change request status after a delay
stage("Approval gate") {
steps {
waitUntil {
sleep 30 // check status after 30s
checkGatingStatus(
site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1'
)
}
}
}
}
Snippet example: Automatically check change request status (poll)
stage("Approval gate") {
steps {
retry(20) { // Retry every 30s for 10min
waitUntil {
sleep 30
checkGatingStatus(
site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1'
)
}
}
}
}
Full Jenkinsfile example
Raise a change request and wait for approval before deploying to production. When the approval is complete, restart the pipeline automatically.
pipeline {
agent any
stages {
stage("Test") {
steps {
echo "Deploying to test"
}
}
stage("Stage") {
steps {
echo "Deploying to staging"
}
}
stage('Request approval') { // Raise change request
steps {
echo 'Raise change request...'
jiraSendDeploymentInfo(site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1',
environmentName:'us-prod-1',
environmentType:'production',
state:"pending",
enableGating:true,
serviceIds: [
'<YOUR-SERVICE-ID>'
]
)
}
}
stage("Approval gate") { // Check change request status
steps {
retry(20) { // Poll every 30s for 10min
waitUntil {
sleep 30
checkGatingStatus(
site:'<YOUR-SITE>.atlassian.net',
environmentId:'us-prod-1'
)
}
}
}
}
stage("Production") {
steps {
echo "Deploying to production!!"
}
post {
always {
sh 'sleep 2'
}
// Notify Jira based on deployment step result
success {
jiraSendDeploymentInfo (
site: '<YOUR-SITE>.atlassian.net',
environmentId: 'us-prod-1',
environmentName: 'us-prod-1',
environmentType: 'production',
state: 'successful',
serviceIds: [
'<YOUR-SERVICE-ID>'
]
)
}
}
}
}
}
Was this helpful?