How to continue a Jenkins build even though a build step failed?

后端 未结 2 650
有刺的猬
有刺的猬 2021-01-21 07:52

I am using a Phing build script with Jenkins and would like to run it end to end on a job and capture all the reports. The problem is it stop building on a failed build step. Is

相关标签:
2条回答
  • 2021-01-21 08:01

    Yes, use try, catch block in you pipeline scripts

    example:

    try {
        // do some stuff that potentially fails
    } catch (error) {
        // do stuff if try fails
    } finally {
        // when you need some clean up to do
    }
    

    Or alternatively if you use sh commands to run these tests, consider running your sh scripts with the "|| true" suffix, this tells the linux sh script to exit with a result code of 0, even if your real command exited with an exit code.

    example:

    stage('Test') {
        def testScript = ""
        def testProjects = findFiles(glob: 'test/**/project.json')
    
        if (!fileExists('reports/xml')) {
            if (!fileExists('reports')) {
                sh "mkdir reports"
            }
            sh "mkdir reports/xml"
        }
    
        for(prj in testProjects) {
            println "Test project located, running tests: " + prj.path
            def matcher = prj.path =~ 'test\\/(.+)\\/project.json'
    
            testScript += "dotnet test --no-build '${prj.path}' -xml 'reports/xml/${matcher[0][1]}.Results.xml' || true\n"
        }
    
        sh testScript
    
    0 讨论(0)
  • 2021-01-21 08:24

    I don't know a lot about Phing but, since it's based on Ant, if the build step you are executing has a "failonerror" attribute you should be able to set it to false so that the entire build doesn't fail if the step returns an error.

    0 讨论(0)
提交回复
热议问题