Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Jenkins Pipeline Input and Approval

Introduction

The Jenkins Pipeline Input and Approval process allows teams to create automated workflows with human intervention at critical points. This lesson covers how to implement and manage inputs and approvals effectively in Jenkins Pipelines.

Key Concepts

  • **Pipeline**: A suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins.
  • **Input Step**: A step in Jenkins Pipeline that pauses the execution and waits for user input.
  • **Approval**: A process where certain stages of the pipeline require validation before proceeding.

Pipeline Input

To add an input step in your Jenkins Pipeline, use the following syntax:

pipeline {
    agent any
    stages {
        stage('Input Stage') {
            steps {
                script {
                    input message: 'Proceed with deployment?', ok: 'Yes'
                }
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying...'
            }
        }
    }
}

This script prompts the user to confirm whether to proceed with the deployment. The pipeline will pause until the user clicks 'Yes'.

Approval Process

The approval process can be integrated using the input step. You might include additional options like specifying a timeout or allowing multiple users to approve.

pipeline {
    agent any
    stages {
        stage('Approval Stage') {
            steps {
                script {
                    def userInput = input(
                        id: 'userInput', 
                        message: 'Authorize deployment?',
                        parameters: [string(name: 'approvedBy', defaultValue: '', description: 'Enter your name')]
                    )
                    echo "Approval granted by: ${userInput}"
                }
            }
        }
    }
}

Best Practices

  • Always provide clear messages in your input steps.
  • Set timeouts to prevent indefinite waits.
  • Limit the scope of approvals to avoid bottlenecks.
  • Log actions taken during approval for audit purposes.

FAQ

What happens if no one responds to the input prompt?

If no response is received within the specified timeout, the pipeline will abort, and an error message will be displayed.

Can I restrict who can approve?

Yes, you can create custom logic to restrict approvals based on user roles or groups within your organization.

Is it possible to have multiple approval steps?

Absolutely! You can chain multiple input steps throughout your pipeline to require approvals at various stages.