Jenkins: Scripted Pipeline – Production environment job confirmation step
Tags: jenkins, devops
Published: 2019-03-19 09:51:38

---
title: Jenkins: Scripted Pipeline – Production environment job confirmation step
published: true
tags: Jenkins,devops
canonical_url: https://rtfm.co.ua/en/jenkins-scripted-pipeline-production-environment-job-confirmation-step/
---

![](https://rtfm.co.ua/wp-content/uploads/2016/01/Jenkins.sh-600x600-e1453134979914.png)We have jobs which have to be executed on a Dev and Production environments via a [Scripted Pipeline](https://jenkins.io/doc/book/pipeline/syntax/#scripted-pipeline).

In such jobs, there are tasks to execute CloudFormation upgrades on an infrastructure or Ansible playbooks to update servers configuration.

To avoid an accidental execution of a Production job I want to have some confirmation step before this job will be started and will do any changes in an environment.

Let’s use [`pipeline-input-step`](https://jenkins.io/doc/pipeline/steps/pipeline-input-step/) and its class `BooleanParameterDefinition`.

Add a `verify()` function:

```
def verify() {
    stage('Verify') {
        def userInput = input(
            id: 'userInput', message: 'This is PRODUCTION!', parameters: [
            [$class: 'BooleanParameterDefinition', defaultValue: false, description: '', name: 'Please confirm you sure to proceed']
        ])
        
        if(!userInput) {
            error "Build wasn't confirmed"
        }
    }
}
```

In the `if(!userInput)` condition here the `userInput` value will be check for _true_ or _false_, by default the _false_ will be set here.

Now add this function execution:

```
node {
    
    switch("${env.LIMIT}") {
        case "backend-production":
            verify()
            echo "Run job"
            break;
        default:
            echo "Dev deploy"
            break;
    }   
}
```

Here we checking the `LIMIT` parameter value which can contain a _backend-production_, _backend-dev,_ or _backend-test_.

If its value will be equal to the _backend-production_ – then the `verify()` first will be executed and only after it – other build/deploy steps.

If any other – then just tasks will be started.

Let’s check it – start a job:

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_182505.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_182505.png)

User input request appeared:

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184514.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184514.png)

Set mark, press _Proceed_:

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184539.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184539.png)

And build is started:

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184554.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184554.png)

Now let’s re-run it but at this time let’s “forget” to set a mark and just press _Proceed_:

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184651.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184651.png)

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184705.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184705.png)

Here the  `if(!userInput)` was applied and the result is the  [`error`](https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#error-error-signal).

And last check – with the _Abort_:

[![](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184754.png "Jenkins: Scripted Pipeline - подтверждение выполнения для Production окружения")](https://rtfm.co.ua/wp-content/uploads/2018/08/Screenshot_20180815_184754.png)

Done.

### Similar posts

- <small>02/08/2017</small> [Jenkins: sandbox.RejectedAccessException: Scripts not permitted to use](https://rtfm.co.ua/jenkins-sandbox-rejectedaccessexception-scripts-not-permitted-to-use/)<small> (0)</small>   
- <small>09/22/2017</small> [Jenkins: Pipeline, Groovy, Ansible и VM provisioning](https://rtfm.co.ua/jenkins-pipeline-groovy-ansible-i-vm-provisioning/)<small> (0)</small>  
- <small>02/09/2017</small> [Azure: подключение дополнительного диска к VM и миграция Jenkins](https://rtfm.co.ua/azure-podklyuchenie-dopolnitelnogo-diska-k-vm-i-migraciya-jenkins/)<small> (0)</small>  
- <small>08/23/2018</small> [Jenkins: wrapper script does not seem to be touching the log file](https://rtfm.co.ua/jenkins-wrapper-script-does-not-seem-to-be-touching-the-log-file/)<small> (0)</small>