Jenkins Manual email approval before deployment

Viewed 3594

I am trying to build a logic for our UAT team to deploy code only upon approval from manager . I would like to know how can be achieved ? Email approval ?. Please help

1 Answers

You can try something like this

//this will grab user - who is running the job
def user
node {
  wrap([$class: 'BuildUser']) {
    user = env.BUILD_USER_ID
  }
  
  emailext mimeType: 'text/html',
                 subject: "[Jenkins]${currentBuild.fullDisplayName}",
                 to: "user@xxx.com",
                 body: '''<a href="${BUILD_URL}input">click to approve</a>'''
}

pipeline {
    agent any
    stages {
        stage('deploy') {
            input {
                message "Should we continue?"
                ok "Yes"
            }
            when {
                expression { user == 'hardCodeApproverJenkinsId'}
            }
            steps {
                sh "echo 'describe your deployment' "
            }
        }
    }
}

you can also get some more help from this StackOverflow question

Related