我正在尝试使用以下代码来执行构建,最后,在构建成功时执行构建后操作.不过,我得到一个MultipleCompilationErrorsException,说我的try块不是有效的section定义.请帮助,我尝试了很多重组块但似乎无法解决问题.
#!/usr/bin/env groovy
pipeline{
agent any
try {
stages{
stage("Parallel 1") {
steps {
parallel (
'firstTask' : {
build( "DSL-Controll-Demo-Fibonacci-1" )
},
'secondTask' : {
build( "DSL-Controll-Demo-Fibonacci-2" )
}
)
}
}
stage("Feature") {
steps {
build( "DSL-Controll-Demo-Fibonacci-5" )
build( "DSL-Controll-Demo-Fibonacci-6" )
}
}
stage("Parallel 2") {
steps{
parallel (
"thirdTask" : {
build( "DSL-Controll-Demo-Fibonacci-3" )
},
"forthTask" : {
build( "DSL-Controll-Demo-Fibonacci-4" )
}
)
}
}
}
}
catch(all) {
currentBuild.result = 'FAILURE'
}
if(currentBuild.result != 'FAILURE') { …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个步骤的管道,例如:
stage 'dev - compile'
node('master') {
//do something
}
stage 'test- compile'
node('master') {
//do something
}
stage 'prod- compile'
node('master') {
//do something
}
Run Code Online (Sandbox Code Playgroud)
我想在工作中出现问题时发送电子邮件,无论错误发生在何处,我都能发送电子邮件,例如:
try {
/**
all the code above
**/
} catch(Exception e) {
mail the error
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用并行步骤进行后故障操作,但它永远不会起作用.
这是我的JenkinsFile:
pipeline {
agent any
stages {
stage("test") {
steps {
withMaven(
maven: 'maven3', // Maven installation declared in the Jenkins "Global Tool Configuration"
mavenSettingsConfig: 'maven_id', // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
mavenLocalRepo: '.repository')
{
// Run the maven build
sh "mvn --batch-mode release:prepare -Dmaven.deploy.skip=true" --> it will always fail
}
}
}
stage("testing") {
steps {
parallel (
phase1: { sh 'echo phase1' },
phase2: { sh "echo phase2" }
)
} …Run Code Online (Sandbox Code Playgroud) 我有以下post失败部分:
post {
failure {
mail subject: "\u2639 ${env.JOB_NAME} (${env.BUILD_NUMBER}) has failed",
body: """Build ${env.BUILD_URL} is failing!
|Somebody should do something about that""",
to: "devel@example.com",
replyTo: "devel@example.com",
from: 'jenkins@example.com'
}
}
Run Code Online (Sandbox Code Playgroud)
我想在错误消息的正文中包含构建失败的原因.
我怎样才能做到这一点?
如果没有,有没有办法将构建日志文件附加到电子邮件?
我遇到过有关此主题的较旧问题。即
但是,到目前为止,我希望 Jenkins Pipeline 能够内置此功能,而不是被黑客入侵。
在 Jenkins Pipeline 中运行post脚本时有什么方法可以找到构建失败吗?例如通过环境变量currentBuild等。
pipeline {
agent none
stages {
stage("Validate") {
parallel {
stage("Ubuntu") {
agent {
label "UBUNTU"
}
steps {
sh "cause failure"
}
}
}
}
}
post {
failure {
sendFailureMessage(`failure reason here`)
}
aborted {
sendFailureMessage(`failure reason here`)
}
unstable {
sendFailureMessage(`failure reason here`)
}
}
}
Run Code Online (Sandbox Code Playgroud)