【问题标题】:Build promotion using jenkinsfile upon approval在获得批准后使用 jenkinsfile 构建促销
【发布时间】:2019-04-09 18:42:46
【问题描述】:

我需要使用 jenkins 文件将我的构建升级为生产,前提是它由使用 servicenow 更改票证的更改管理或手动批准进行批准。

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

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

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

提前致谢! 皮尤什

【问题讨论】:

    标签: .net jenkins jenkins-pipeline


    【解决方案1】:

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

    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."
                }
    
            }    
        }  
    }
    

    可选:您可以用超时包围它,这样它就不会永远等待。

    有几种不同的方式来发送电子邮件,但这是其中之一:

    // 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']]
    )
    

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

    【讨论】:

    • 感谢您提供宝贵的意见,但是,我不是开发人员,我的编码技能也达不到标准,您有空也可以分享一下电子邮件的代码。我非常感谢你在这方面的努力。干杯!
    • 我用电子邮件示例修改了我的帖子。
    • 非常感谢!我非常感谢您的努力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    相关资源
    最近更新 更多