相关疑难解决方法(0)

Jenkins管道脚本中的try-catch块

我正在尝试使用以下代码来执行构建,最后,在构建成功时执行构建后操作.不过,我得到一个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)

groovy try-catch jenkins jenkins-pipeline

15
推荐指数
5
解决办法
6万
查看次数

通过在Pipeline(以前称为工作流程)中发送邮件,jenkins通知错误在不同的步骤中发生

我有一个包含多个步骤的管道,例如:

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)

jenkins jenkins-pipeline

5
推荐指数
2
解决办法
9961
查看次数

发布失败JenkinsFile无效

我正在尝试使用并行步骤进行后故障操作,但它永远不会起作用.

这是我的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)

jenkins jenkins-pipeline

5
推荐指数
1
解决办法
8549
查看次数

在Jenkinsfile失败时获取错误原因

我有以下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 jenkins-pipeline

5
推荐指数
1
解决办法
3561
查看次数

Jenkins Pipeline 失败原因

我遇到过有关此主题的较旧问题。即

但是,到目前为止,我希望 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)

jenkins jenkins-pipeline

5
推荐指数
1
解决办法
1666
查看次数

标签 统计

jenkins ×5

jenkins-pipeline ×5

groovy ×1

try-catch ×1