【问题标题】:Implementation of Manual Approval in Continuous Delivery using Kubernetes and Jenkins使用 Kubernetes 和 Jenkins 在持续交付中实现手动审批
【发布时间】:2019-12-19 19:28:51
【问题描述】:

目前我正在尝试使用 Kubernetes 和 Jenkins 实现持续交付和部署的示例。我已经成功实现了持续部署。我的 REST API 自动通过 Jenkins 部署到我的 Kubernetes 集群。 test 和 prod 命名空间都在部署。

现在我正在尝试通过在发布到 prod 命名空间之前进行手动用户批准来实现持续交付。意味着通过在测试和生产环境之间实现一次切换来实现手动批准。

为了更清楚,我在这里添加了我在探索时获得的屏幕截图,

人工审批中持续交付和持续部署的区别

我的困惑是,当我实施交付时,如何添加用户交互?我需要更改deployment.yamlservice.yaml 中的任何参数吗?或者当我在 Jenkins UI 中创建我的 Jenkins 管道作业时,我是否需要更改任何内容?

我是持续交付方面的新手。任何人都可以建议任何文档或教程或任何探索方法吗?

【问题讨论】:

  • “进行用户交互”是什么意思?
  • 手动需要在部署到测试后批准部署到 prod。在交付过程中直到 prod 不是自动化的。在这之间,需要通过在其之间进行切换来手动允许。我在这里指的是手动过程。我希望你能明白我想说什么。感谢您对我的讨论的回应先生。
  • 如果你使用 Jenkinsfile - 这可以使用jenkins.io/doc/pipeline/steps/pipeline-input-step来实现
  • @VishalBiyani - 如果您清楚地将此信息更新为答案,我可以将其标记为答案。我已经实施并成功地通过手动批准部署到生产版本。谢谢您的回复先生。
  • 感谢@Jacob - 添加了答案!

标签: jenkins kubernetes continuous-delivery


【解决方案1】:

您可以使用Jenkins Input Step 来执行此类操作。输入步骤加上try/catch 将使您能够很好地控制工作的成功/失败。

example below is from CloudBees support 门户并使用输入框,捕获输入并使用该输入值来设置当前构建的成功/失败

def userInput
try {
    userInput = input(
        id: 'Proceed1', message: 'Was this successful?', parameters: [
        [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']
        ])
} catch(err) { // input false
    def user = err.getCauses()[0].getUser()
    userInput = false
    echo "Aborted by: [${user}]"
}

node {
    if (userInput == true) {
        // do something
        echo "this was successful"
    } else {
        // do something else
        echo "this was not successful"
        currentBuild.result = 'FAILURE'
    } 
}

【讨论】:

    【解决方案2】:

    我们在 Jenkins 中使用了一个共享库。我们将暂停管道 1 天,并通过链接向 AD 中提及的 Approval DL 发送邮件。如果没有及时批准,我们将终止部署。

    批准必须使用部署批准的链接登录 jenkins。 (我们考虑过直接批准链接,但这是一个安全风险。)

    timeout(time: 1, unit: "DAY")
    {
      log("Send an email to approvers@example.net with link)
      sendEmail()
      def inputResult = input (
      id: "123", 
      message: "I approve this deployment",
      )
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 2016-09-26
      相关资源
      最近更新 更多