0

在我的管道中,我在 docker 容器中运行测试用例,然后将一些目录从 docker 容器复制到 Jenkins 工作区。

不需要所有目录都存在于 docker 容器中(例如,根据失败的测试,屏幕截图目录可能存在或不存在)。如何在从 docker 容器复制目录或文件之前检查目录或文件是否存在。

这是我在管道中提到的部分

 post {
        always {
            echo 'Generating Test Reports ...'
            sh 'make posttest'
            echo('Copying Test Files ...')
            sh 'docker cp container-name:/app/results/mochareports/assets/videos ./results'
            sh 'docker cp container-name:/app/results/mochareports/assets/screenshots ./results'
            sh 'docker cp container-name:/app/results/mochareports/report.html ./results'
            echo 'Publish Test Reports ...'
            publishHTML (target : [allowMissing: false,
                alwaysLinkToLastBuild: true,
                keepAll: true,
                reportDir: 'results/mochareports',
                reportFiles: 'report.html',
                reportName: 'Cypress Test Reports',
                reportTitles: 'The test report'])
            echo 'Destroy Build'
            sh 'make destroy'
            cleanWs()
        }
    }
4

1 回答 1

0

Groovy 方式是使用fileExists https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#fileexists-verify-if-file-exists-in-workspace

if(fileExists('/app/results/mochareports/assets/screenshots/')) {
  ...
}
于 2022-02-14T17:52:32.097 回答