批准后使用jenkinsfile进行升级 [英] Build promotion using jenkinsfile upon approval

查看:64
本文介绍了批准后使用jenkinsfile进行升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有在通过servicenow变更票证或手动批准的变更管理批准后,我才需要使用jenkins文件将其构建升级到生产环境.

I need to promote my build to production using jenkins file only if it is approved by change management using servicenow change ticket ticket or by manual approval.

我想要类似的东西: -产品构建只有在获得经理批准后才能手动触发(他/她应收到带有批准/拒绝链接的批准邮件) 或者 -如果与变更相关联的ServiceNow变更票证被所有批准者批准,如果(changeticket =="APPROVED"),则可以在生产中触发构建部署.

I want something like: - Prod build can only be triggered manually if it is approved by manager(he/she should receive the approval mail with the link to approve/reject) or - if the ServiceNow change ticket associated with the change is approved by all the approvers, if (changeticket== "APPROVED") then you can trigger the build deployment in production.

我的jenkinsfile看起来像这样(这是示例代码)

My jenkinsfile would look something like this(this is a sample code)

  pipeline {
  agent any
  environment {
  dotnet = 'path\to\dotnet.exe'
              }

  stages {
  stage('Checkout') {
  steps {
  git credentialsId: 'userId', url: 
  'https://github.com/NeelBhatt/SampleCliApp', branch: 'master'
     }
         }
   stage('Restore PACKAGES') {
   steps {
    bat "dotnet restore --configfile NuGet.Config"
         }
                              }
   stage('Clean') {
   steps {
   bat 'dotnet clean'
         }
                  }
   stage('Build') {
   steps {
   bat 'dotnet build --configuration Release'
         }
                 }
   stage('Pack') {
   steps {
   bat 'dotnet pack --no-build --output nupkgs'
         }
                 }
   stage('Publish') {
   steps {
   bat "dotnet nuget push **\\nupkgs\\*.nupkg -k yourApiKey -s            
   http://myserver/artifactory/api/nuget/nuget-internal-stable/com/sample"
         }
                    }
      }
      }

提前谢谢! 皮尤什

推荐答案

您需要在我们的管道中添加一个INPUT步骤,以请求用户输入并对结果采取行动.在您的情况下,您可以添加一个电子邮件步骤,以将电子邮件链接发送到此管道,以请求批准.输入步骤获得批准后,部署步骤将执行.

You need to add an INPUT step in our Pipeline to ask for user input and take action on the result. In your case, you can add an email step to send an email link to this Pipeline that will ask for an approval. And the Deployment step will take action after the Input step has been approved.

stage("Stage with input") {
    steps {
      def userInput = false
        script {
            def userInput = input(id: 'Proceed1', message: 'Promote build?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']])
            echo 'userInput: ' + userInput

            if(userInput == true) {
                // do action
            } else {
                // not do action
                echo "Action was aborted."
            }

        }    
    }  
}

(可选):您可以在超时周围加上它,这样它就不会永远等待.

Optionally: You can surround this with a timeout so it won't wait forever.

有几种发送电子邮件的方法,但这是其中一种:

There are a few different ways to send an email, but this is one of them:

// send to email
emailext (
  subject: "Waiting for your Approval! Job: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
  body: """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
              <p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
  recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)

请根据您的需要进行修改.

Please modify to suit your needs.

这篇关于批准后使用jenkinsfile进行升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆