经批准后使用 jenkinsfile 建立促销

piy*_*eva 2 .net jenkins jenkins-pipeline

仅当更改管理使用 servicenow 更改票证或手动批准批准时,我才需要使用 jenkins 文件将我的构建升级为生产。

我想要类似的东西: - 只有在经理批准后才能手动触发产品构建(他/她应该收到带有批准/拒绝链接的批准邮件)或者 - 如果与更改相关的 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"
         }
                    }
      }
      }
Run Code Online (Sandbox Code Playgroud)

提前致谢!皮尤什

Ant*_*ios 5

您需要在我们的流水线中添加一个 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."
            }

        }    
    }  
}
Run Code Online (Sandbox Code Playgroud)

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

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

// 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']]
)
Run Code Online (Sandbox Code Playgroud)

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