首页 > 解决方案 > Jenkins 在部署前手动批准电子邮件

问题描述

我正在尝试为我们的 UAT 团队构建一个逻辑,以便仅在经理批准后部署代码。我想知道怎样才能实现?电子邮件批准?请帮忙

标签: jenkinsjenkins-pipeline

解决方案


你可以试试这样的

//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' "
            }
        }
    }
}

您还可以从这个StackOverflow 问题中获得更多帮助


推荐阅读