只有当变更管理使用servicenow变更票证或手动审批通过时,我才需要使用jenkins文件将我的构建升级到生产环境。
我想要类似这样的内容:- Prod build只能在经理批准的情况下手动触发(他/她应该收到带有批准/拒绝链接的批准邮件),或者-如果与更改关联的ServiceNow变更票证得到所有审批人的批准,如果(changeticket==“已批准”),则您可以在生产中触发构建部署。
我的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"
}
}
}
}提前感谢!皮尤什
发布于 2018-10-04 04:09:32
您需要在我们的Pipeline中添加一个输入步骤,以请求用户输入并对结果执行操作。在您的情况下,您可以添加一个电子邮件步骤,将电子邮件链接发送到此管道,以请求批准。并且部署步骤将在输入步骤被批准之后采取行动。
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 "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)请根据您的需要进行修改。
https://stackoverflow.com/questions/52631693
复制相似问题