Ensuring Safety: Adding Manual Approvals in Jenkins Pipelines
- Published on
Ensuring Safety: Adding Manual Approvals in Jenkins Pipelines
Jenkins is a popular automation server used for continuous integration and delivery. Jenkins pipelines allow you to define delivery pipelines using code, and Jenkins Blue Ocean provides a user-friendly interface for creating and visualizing these pipelines.
In some cases, it is essential to include manual approvals in your pipeline, especially when dealing with critical changes that need human validation before deployment. In this blog post, we will explore how to add manual approvals in Jenkins pipelines to ensure safety and control over the deployment process.
Why Manual Approvals?
Manual approvals are crucial in the deployment process for several reasons:
- Quality Control: Manual approvals allow designated stakeholders to ensure that the deployed changes meet quality standards and align with business requirements.
- Risk Mitigation: Manual intervention provides an additional layer of safety, especially when dealing with critical or sensitive deployments.
- Compliance: In regulated industries, manual approvals are often a requirement to ensure compliance with organizational or industry-specific policies.
Adding Manual Approvals to Jenkins Pipelines
To demonstrate the addition of manual approvals in Jenkins pipelines, we will create a simple pipeline that includes a stage requiring manual approval before proceeding with the deployment.
Prerequisites
Before proceeding, ensure that you have the following:
- Jenkins installed and configured
- A Jenkins pipeline defined either in a Jenkinsfile within your code repository or directly within the Jenkins web interface
Step 1: Define Pipeline Stage for Manual Approval
pipeline {
agent any
stages {
stage('Build') {
steps {
// Your build steps here
}
}
stage('Test') {
steps {
// Your test steps here
}
}
stage('Manual Approval') {
steps {
script {
// Add a prompt for manual approval
input message: 'Deploy to production?'
}
}
}
stage('Deploy') {
when {
expression {
// Add condition to deploy only if manually approved
currentBuild.rawBuild.causes.any { it.shortDescription == 'Started by an SCM change' }
}
}
steps {
// Your deployment steps here
}
}
}
}
In this example, we have added a stage called 'Manual Approval' that contains a script block with the input
step. This step will pause the pipeline and prompt the user with the specified message, waiting for manual approval to proceed.
Step 2: Run the Pipeline and Approve Deployment
Upon reaching the 'Manual Approval' stage, the pipeline execution will pause, and a user interface will prompt the designated approver to approve or reject the deployment. Once approved, the pipeline will proceed with the deployment stage.
Benefits of Manual Approvals in Jenkins Pipelines
Adding manual approvals to Jenkins pipelines offers several benefits:
Enhanced Control and Oversight
Manual approvals provide an additional layer of control, allowing designated approvers to closely monitor and sign off on critical deployments, ensuring that only verified changes are pushed to production.
Compliance and Audit Trails
For organizations operating in regulated environments, manual approvals contribute to compliance efforts by ensuring that all changes go through a documented approval process, thereby contributing to comprehensive audit trails.
Risk Mitigation
By introducing manual intervention, teams can mitigate risks associated with automated deployments, especially in scenarios where human judgment is indispensable before proceeding with critical changes.
Key Takeaways
Incorporating manual approvals into Jenkins pipelines is a best practice for ensuring safety, compliance, and control in the software deployment process. By following the simple steps outlined in this post, you can add an essential layer of human validation to your continuous delivery pipelines, mitigating risks and ensuring that only approved changes are deployed.
Adding manual approvals ensures that crucial changes are thoroughly validated before reaching production, ultimately contributing to a robust and reliable deployment process.
For more information on Jenkins pipelines and best practices, check out the official Jenkins documentation and explore the wealth of resources available within the vibrant Jenkins community.
Are you ready to ensure safety and control in your Jenkins pipelines with manual approvals? Implement this best practice today and elevate your deployment process to new heights of reliability and compliance.