How can I approve a deployment and add an optional delay for the deployment

Table of contents

No heading

No headings in the article.

To solve the problem of role based approval i used input block with submitter. This means that person who listed as the submitter will only be able to give stage approvals.

    stage('Approval') {
        agent none
        steps {
            script {
                def deploymentDelay = input id: 'Deploy', message: 'Deploy to production?', submitter: 'rkivisto,admin', parameters: [choice(choices: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'], description: 'Hours to delay deployment?', name: 'deploymentDelay')]
                sleep time: deploymentDelay.toInteger(), unit: 'HOURS'
            }
        }
    }

Please note there submitter must be a valid user. Use role based access plugin and create a user with relevant access.

https://docs.cloudbees.com/docs/cloudbees-ci-kb/latest/client-and-managed-controllers/how-can-i-approve-a-deployment-and-add-an-optional-delay-for-the-deployment