Services DevOps DevSecOps Cloud Consulting Infrastructure Automation Managed Services AIOps MLOps DataOps Microservices 🔐 Private AINEW Solutions DevOps Transformation CI/CD Automation Platform Engineering Security Automation Zero Trust Security Compliance Automation Cloud Migration Kubernetes Migration Cloud Cost Optimisation AI-Powered Operations Data Platform Modernisation SRE & Observability Legacy Modernisation Managed IT Services 🔐 Private AI DeploymentNEW Products ✨ ZippyOPS AINEW 🛡️ ArmorPlane 🔒 DevSecOpsAsService 🖥️ LabAsService 🤝 Collab 🧪 SandboxAsService 🎬 DemoAsService Bootcamp 🔄 DevOps Bootcamp ☁️ Cloud Engineering 🔒 DevSecOps 🛡️ Cloud Security ⚙️ Infrastructure Automation 📡 SRE & Observability 🤖 AIOps & MLOps 🧠 AI Engineering 🎓 ZOLS — Free Learning Company About Us Projects Careers Get in Touch

Jenkins Pipeline for Controlled Production Deployment

Jenkins Pipeline for Controlled Production Deployment

A Jenkins Pipeline streamlines the process of automating software delivery from version control to production. It plays a crucial role in continuous delivery (CD) by managing the entire workflow, ensuring software is delivered smoothly and securely to end users. In this guide, we’ll explore how to implement a Jenkins pipeline that triggers production builds only after obtaining proper approvals.

Jenkins pipeline automation with approval steps for production deployment

Understanding Jenkins Pipeline in Continuous Delivery

The Jenkins pipeline is a suite of plugins that helps implement continuous delivery pipelines within Jenkins. These pipelines automate the process of building, testing, and deploying code, which results in faster and more reliable software delivery.

However, when deploying to a production environment, extra precautions are often necessary. Organizations need to ensure that code changes are approved before going live. This can be achieved by integrating approval steps into the Jenkins pipeline, making it more controlled and secure.

Setting Up the Approval Process in Jenkins Pipeline

In some workflows, you may need to trigger the production build manually or after approval from a designated manager. A common scenario would be that the Jenkins pipeline only deploys the production build if it has been approved through either an email approval or by linking it to a ServiceNow change request.

For example:

  • The production build can only be triggered manually if it has been approved by a manager. The manager receives an email containing a link to approve or reject the deployment.
  • Alternatively, if the ServiceNow change ticket associated with the deployment is approved by all necessary parties, the build can be triggered automatically.

Sample Jenkinsfile for Controlled Production Deployment

Here’s a simplified example of a Jenkinsfile that incorporates the steps mentioned above:

stages {
  stage('Checkout') {
    steps {
      git credentialsId: 'userId', url: 'https://github.com/NeelBhatt/SampleCliApp', branch: 'master'
    }
  }
  stage('Restore Packages') {
    steps {
      bat "dotnet restore --configfile NuGet.Config"
    }
  }
  stage('Clean') {
    steps {
      bat 'dotnet clean'
    }
  }
  stage('Build') {
    steps {
      bat 'dotnet build --configuration Release'
    }
  }
  stage('Pack') {
    steps {
      bat 'dotnet pack --no-build --output nupkgs'
    }
  }
  stage('Publish') {
    steps {
      bat "dotnet nuget push **\\nupkgs\\*.nupkg -k yourApiKey -s http://myserver/artifactory/api/nuget/nuget-internal-stable/com/sample"
    }
  }
}

This pipeline automates the process of checking out the code, restoring packages, cleaning the environment, building the code, packaging it, and finally pushing it to the package registry. However, you can modify the pipeline to add an additional manual approval step before proceeding with production deployment.

Adding a User Input Step for Approval

In addition to the automated pipeline steps, you can add an input step to the Jenkins pipeline to ask for manual approval before proceeding with deployment. This step ensures that production deployments are only triggered after the necessary approvals are obtained.

Here’s an example of how to add this input step in the Jenkinsfile:

stage('Stage with input') {
  steps {
    def userInput = false
    script {
      userInput = input(id: 'Proceed1', message: 'Do you approve this build for production?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm approval']])
      echo 'User input: ' + userInput

      if (userInput == true) {
        // Continue deployment action
      } else {
        echo "Deployment aborted."
      }
    }
  }
}

In this example, a simple Boolean parameter is used to confirm whether the build should proceed. After the approval, the deployment actions can be triggered, or the deployment can be aborted if the approval is denied.

Automating Approval Notifications via Email

To automate the approval process, you can use Jenkins email notifications. This allows you to send approval requests to relevant stakeholders, making it easier for them to approve or reject a deployment.

Here’s an example of how to send an email for approval:

emailext(
  subject: "Waiting for your Approval! Job: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
  body: """STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
          Check the console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"
  """,
  recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)

This email will notify the team members responsible for approving the build, allowing them to take action via a simple click.

Enhancing Your Deployment Jenkins Pipeline with ZippyOPS

In modern DevOps environments, integrating tools for DevSecOps, MLOps, and AIOps into your Jenkins pipeline can significantly enhance your automation. By combining your Jenkins pipeline with ZippyOPS, you can streamline the entire CI/CD pipeline and incorporate practices like Cloud Automation, Microservices, and Automated Infrastructure Management.

ZippyOPS offers consulting, implementation, and managed services to optimize your DevOps pipeline. Whether you need DevOps, DataOps, or advanced AIOps for complex environments, ZippyOPS has the tools and expertise to accelerate your deployment process.

Explore more about how ZippyOPS can help your organization by visiting their solutions page or checking out their service offerings.

Conclusion: Managing Production Deployments with Confidence

By adding manual approval steps to your Jenkins pipeline, you can ensure that production deployments are well-managed and secure. With the right integrations, such as ServiceNow for change management or automated emails for approval requests, you can automate most of your pipeline while maintaining control over critical deployment steps.

For enterprises looking to further streamline their deployment processes and enhance their DevOps capabilities, ZippyOPS provides expert consulting and managed services. Reach out to ZippyOPS today to learn how their Cloud, Microservices, and Automated Ops solutions can optimize your workflows.

Ready to improve your DevOps pipeline? Contact us at sales@zippyops.com.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top