【问题标题】:Docker Multi Stage Build access Test Reports in Jenkins when Tests Fail测试失败时,Docker 多阶段构建访问 Jenkins 中的测试报告
【发布时间】:2021-05-31 12:09:58
【问题描述】:

我正在 docker 中进行多阶段构建,以将应用程序与测试分开。现在在我的 Dockerfile 中的某个时间点运行:

RUN pytest --junit=test-reports/junit.xml

分别在我的 Jenkinsfile 中:

def app = docker.build("app:${BUILD_NUMBER}", "--target test .")
app.inside {
  sh "cp -r /app/test-reports test-reports"
}

junit 'test-reports/junit.xml'

现在,如果我的测试失败,构建失败,这很好。但是该阶段的其余部分没有执行,即我无权访问 test-reports 文件夹。我该如何处理?

【问题讨论】:

    标签: docker jenkins continuous-integration pytest docker-multi-stage-build


    【解决方案1】:

    我通过在构建阶段后使用 always 块解决了类似的任务。 请检查以下代码是否有帮助。

    always{
        script{
            sh '''#!/bin/bash
            docker create -it --name test_report app:${BUILD_NUMBER} /bin/bash
            docker cp test_report:/app/test-reports ./test-reports
            docker rm -f test_report
            '''
        }
    
        junit 'test-reports/junit.xml'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 2013-05-23
      • 2015-11-15
      • 2012-09-22
      • 2016-01-04
      • 1970-01-01
      • 2019-10-17
      相关资源
      最近更新 更多