【问题标题】:My jenkinsfile does not compile anymore when trying to add a post build action尝试添加构建后操作时,我的 jenkinsfile 不再编译
【发布时间】:2019-01-29 13:13:15
【问题描述】:

尝试添加 POST 操作时,我的 jenkinsfile 不再编译。最后一个应该在构建结束时显示到詹金斯控制台输出。

第一部分是关于我的 jenkinsfile 代码,其中的构建做得很好。

第二部分是添加到第一部分的补丁,任何构建都会失败。

我想整合第一部分和第二部分以获得下文所述的预期输出,但无论插入方式如何,整合都会失败。 我已经尝试了很多东西,但现在我被卡住了,所以任何帮助都将不胜感激。

// 第一部分:我的基本代码

    node {
    def mvnHome
    stage('Preparation') { 
        git 'https://github.com/jglick/simple-maven-project-with-   tests.git'
      // Get the Maven tool.
      // ** NOTE: This 'M3' Maven tool must be configured
      // **       in the global configuration.           
      mvnHome = tool 'M3'
   }
    stage('Build') {
      // Run the maven build
      if (isUnix()) {
         sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
      } else {
         bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
      }
   }
   stage('Results') {
      junit '**/target/surefire-reports/TEST-*.xml'
      archiveArtifacts 'target/*.jar'
   }
 }

// 第二部分:添加到前面代码的代码

post {
    always {
        echo 'I have finished and deleting workspace'
        // deleteDir() 
    }
    success {
        echo 'Job succeeeded!
    }
    unstable {
        echo 'I am unstable :/'
    }
    failure {
        echo 'I failed :('
    }
    changed {
        echo 'Things were different before...'
    }
}

控制台输出中的预期输出:'作业成功!或者我不稳定:/或'我失败了:(' ...取决于詹金斯的构建状态,并且总是在每次新构建之前清理工作区

实际结果是来自控制台输出的错误消息: java.lang.NoSuchMethodError:在步骤 [archive、bat、build、catchError、checkout、deleteDir、dir ......

【问题讨论】:

标签: jenkins jenkins-pipeline pipeline


【解决方案1】:

您正在混淆脚本式和声明式管道语法。 post 是声明式的一部分,但您使用脚本变体(不是 pipeline,而是 node 步骤)。

你必须使用try/catch

the documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多