Jenkins spring boot example, Jenkins spring boot github, Jenkins spring boot tutorial, Spring Boot Jenkins Docker, Spring boot Jenkins pipeline example github, Jenkins pipeline spring Boo

Jenkins Manual Approval Tutorial for Beginners Spring Boot Example

Jenkins spring boot example, Jenkins spring boot github, Jenkins spring boot tutorial, Spring Boot Jenkins Docker, Spring boot Jenkins pipeline example github, Jenkins pipeline spring Boo

Jenkins is a versatile tool for automating your CI/CD pipelines. However, automation isn’t always the answer—there are times when you need human intervention to ensure quality, perform compliance checks, or involve stakeholders in critical decisions. This is where manual approval steps in Jenkins come into play. If you’re new to Jenkins or want to learn how to incorporate manual approvals effectively, this guide is for you.

By the end, you’ll have a clear understanding of Jenkins manual approvals, how to integrate them into your pipelines, and useful troubleshooting tips.

Table of Contents

  1. What is Jenkins Manual Approval?
  2. Basic Pipeline Setup
  3. Adding Input Step to Jenkinsfile
  4. Trigger Pipeline Manually
  5. Handling Timeout and Abort
  6. Approval by Specific User
  7. Simple Use Case Walkthrough
  8. Debugging Manual Steps
  9. Advanced Options Overview
  10. Wrap-Up and Resources
  11. FAQs

What is Jenkins Manual Approval?

Jenkins manual approval is a feature that allows you to pause an automated pipeline at a certain stage to seek human intervention. This step requires an authorized person or team member to approve before the pipeline continues. The manual approval process is commonly used in CI/CD workflows to achieve:

  • Compliance checks – Ensuring all updates meet regulatory or organizational requirements.
  • Code quality reviews – Performing additional testing or stakeholder reviews before deployment.
  • Controlled releases – Limiting code promotions to production environments only after careful evaluation.

This feature adds a layer of control to your pipelines, making them more secure and reliable. You can integrate manual approvals in both declarative and scripted pipelines using the input step.


Basic Pipeline Setup

Before you can add a manual approval step, you need a functioning Jenkins pipeline. Here’s how to create a basic Jenkins pipeline:

Setting Up Your Pipeline

  1. Log in to Jenkins and click New Item on the dashboard.
  2. Select Pipeline as the item type. Name your pipeline appropriately (e.g., “MyFirstPipeline”).
  3. Under the Pipeline tab, enter your Jenkinsfile script or link it to a Git repository.
  4. Save your configuration and trigger your pipeline to ensure it runs without errors.

A basic pipeline script might look like this:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...'
            }
        }
    }
}

This pipeline simply builds and tests your application without pauses. We’ll add manual approval to enhance it.


Adding Input Step to Jenkinsfile

The input directive is what enables manual approvals in Jenkins. Adding this step to a Jenkinsfile pauses the pipeline and prompts for user action.

Example Code:

stage('Await Approval') {
    steps {
        input message:'Do you approve this deployment?', ok:'Yes, deploy'
    }
}

What This Means:

  • message: This is the question displayed to the approver.
  • ok: The button label for confirming the action.

This configuration stops the pipeline and waits for approval before moving on to the next stage.

You can customize the prompt further, even restricting who is allowed to approve the step. We’ll cover this in the “Approval by Specific User” section.

For more on input, refer to Jenkins’ Pipeline Syntax Reference.


Trigger Pipeline Manually

By default, a Jenkins pipeline can be triggered automatically based on changes in the source code repository. However, to maintain full control during development, you can initiate a pipeline manually.

Steps to Trigger Manually:

  1. From the Jenkins dashboard, go to your pipeline’s project page.
  2. Click the Build Now button.
  3. Monitor the pipeline progress in the Build History panel or click on a specific build for logs.

Manual triggering is particularly useful when testing new pipelines or when integrating manual approvals for the first time.


Handling Timeout and Abort

Sometimes approvals may be delayed or forgotten, leading pipelines to remain paused indefinitely. To avoid this, you can configure a timeout for the approval step.

Adding Timeout:

stage('Manual Approval') {
    steps {
        timeout(time: 30, unit: 'MINUTES') {
            input message:'Approve deployment within 30 minutes.'
        }
    }
}

This configuration automatically aborts the pipeline if no action is taken within 30 minutes. It ensures that stalled approvals won’t block the pipeline unnecessarily.

Handling Abort:

When a pipeline aborts, Jenkins will show the build status as “Aborted.” You can also create post-abort tasks to log incidents, notify team members, or clean up resources.

For example:

post {
    aborted {
        echo 'Pipeline was aborted due to timeout.'
    }
}

Approval by Specific User

Restricting who can approve a manual gate is critical in collaborative pipelines. Use the submitter field in the input step to define authorized approvers.

Example:

stage('Approval Required') {
    steps {
        input message:'Deploy to production?', ok:'Proceed', submitter:'admin,user1'
    }
}

This configuration ensures that only the assigned users (e.g., admin, user1) can approve the pipeline. Unauthorized users won’t be able to continue the workflow.


Simple Use Case Walkthrough

Imagine a scenario where you want to ensure human review before deploying changes into the production environment. Here’s the complete sample pipeline:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building the application.'
            }
        }
        stage('Approval Required') {
            steps {
                input message:'Do you approve deploying this change?', ok:'Deploy Now', submitter:'teamLead'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying to production...'
            }
        }
    }
}

This pipeline has three stages:

  1. Build phase for preparing your application.
  2. A manual approval stage for review.
  3. Deployment only after approval.

Debugging Manual Steps

If the manual approval step doesn’t behave as expected, consider these troubleshooting tips:

  1. Check User Permissions: Ensure the approver has the necessary roles or access.
  2. Verify Pipeline Logs: Look for errors or timeout messages in the Jenkins console output.
  3. Notification Setup: If using notifications, confirm that alerts are being sent correctly.

Refer to the Jenkins Troubleshooting Guide for additional assistance.


Advanced Options Overview

For more complex pipelines, you can extend manual approvals with advanced setups, such as:

  • Conditional Logic: Use the when directive to trigger approvals only for specific stages or environments (e.g., production).
  • Parameter Inputs: Gather additional data or context during the approval step, like reasons for deployment decisions.
  • Role-Based Access: Integrate Jenkins with external access management tools like LDAP for enhanced control.

Wrap-Up and Resources

Manual approvals in pipelines create a perfect balance between automation and human oversight. Implementing them in Jenkins ensures smoother workflows, higher quality control, and fewer deployment risks. With the input step, you have a customizable and secure mechanism to involve stakeholders at critical decision points.

Additional Resources:


FAQs

Q1. Can I add multiple manual approval steps?

Yes, you can include as many input steps as needed in your pipeline.

Q2. What happens if no one approves the manual step?

Unless timeouts are defined, the pipeline will remain paused indefinitely.

Q3. Can specific users approve certain stages?

Yes, use the submitter field in the input directive to restrict approvals to specific individuals.

Q4. Is manual approval available in Freestyle projects?

No, manual approvals are specific to pipelines defined using Jenkinsfiles.

Q5. How do I notify users about pending approvals?

Use plugins like the Email Extension Plugin or integrate with Slack for real-time notifications.

Master Jenkins manual approvals, and take your pipelines to the next level of security and control!

Similar Posts