简体   繁体   English

詹金斯管道总是失败

[英]Jenkins Pipeline always fails

My Jenkins pipeline stages are all successful yet the build always says it failed. 我的Jenkins管道阶段都很成功,但构建总是说它失败了。 To be clear, the build was a success and I would like it to register with Jenkins as successful but for some reason Jenkins thinks it has failed. 为了清楚起见,构建是成功的,我希望它与Jenkins注册成功,但出于某种原因詹金斯认为它失败了。 All the stages say success in the dashboard yet the build is marked with a red ball and the console output ends with Finished: FAILURE . 所有阶段都表示在仪表板中成功,但构建标记为红色球,控制台输出以Finished: FAILURE结束。

Here is my pipeline file 这是我的管道文件

node {
    try{
        stage 'Clone repo'
        sh 'gcloud source repos clone <repo-name> --project=<project-name>'
        dir('<repo-name>') {
            try{
                stage 'Run tests'
                sh './gradlew test'
                stage 'Run integration tests'
                sh './gradlew integrationTest'
                publishHTML(target: [
                    allowMissing: false, 
                    alwaysLinkToLastBuild: false, 
                    keepAll: false, 
                    reportDir: '<repo-name>/build/reports/integrationTest', 
                    reportFiles: 'index.html', 
                    reportName: 'Integration Test Reports'])
            } finally {
                stage 'Stop and remove docker containers'
                sh 'docker-compose down'
                sh 'docker-compose rm -f'
            }
        }
    } finally {
        deleteDir()
    }
}

I realised I had included the full path to the html reports when I was actually inside a dir block. 我意识到当我实际进入dir块时,我已经包含了html报告的完整路径。 There was no indication in the logs of this. 日志中没有任何迹象表明这一点。

is your problem solved ? 你的问题解决了吗?

Anyway the deleteDir function can be a problem sometimes. 无论如何,deleteDir函数有时可能是个问题。 Because deleteDir recursively deletes the current directory and its contents, you can raise an error if you try to delete the complete job workspace. 由于deleteDir以递归方式删除当前目录及其内容,因此如果尝试删除整个作业工作区,则可能会引发错误。

Take care to use it in a dir function as below: 注意在dir函数中使用它,如下所示:

dir('directoryToDelete') {
    deleteDir()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM