Jenkins Declarative Pipeline

Sample Jenkins Declarative Pipeline
def A = false
def B = true
pipeline {
    agent any
    tools {
        maven 'MVN'
        jdk 'JDK'
    }
    stages {
        stage('Build Stage') {
            steps {
                git "https://github.com/nishantautomationlabs/nal-junitmockito.git"
                sh "mvn -U clean compile install -DskipTests"
                echo 'Build Stage executed'
            }
        }
        stage('Unit Test Stage') {
            steps {
                sh "mvn -Dtest=MockitoExampleTest test"
                echo 'Unit Test Stage executed'
            }
        }
        stage('Master Stage'){
            when{
                branch 'master'
            }
            steps {
                echo 'run this stage only if its running on the master branch'
            }
        }
        stage('Conditional Stage') {
            when {
                expression { return A || B }
            }
            steps {
                echo 'Conditional stage executed'
            }
        }
        stage('Manual Sign Off') {
            steps {
                echo 'Run manual sign off and click proceed to go to deployment'
                input('Do you want to proceed?')
            }
        }
        stage("Custom Confirmation Check") {
            steps {
                echo 'Run manual sign off and click proceed to go to deployment'
                customConfirmationDialog()
            }
        }
        stage('Deployment stage') {
            steps {
                echo 'Deployed the build successfully'
            }
        }
    }
}

private String customConfirmationDialog() {
    def userInput = input(
            id: 'userInput', message: 'manual sign off?', ok: 'SIGN OFF',
            parameters: [
                    choice(name: 'QA sign off', choices: "Yes\nNo", description: 'All tests passed ? yes/no')
            ])
    println " userInput manual QA choice ++++++++++++++++ :" + userInput
    return userInput
}
Jenkins Configuration:
Build History:

Comments

Popular posts from this blog

Get rid of "Timed out receiving message from renderer"

Setup Selenium Grid using Kubernetes

Launching Selenium Grid and Registering a Web Node