【发布时间】:2020-11-26 22:01:43
【问题描述】:
我有一个管道,其中前 2 个阶段是一个用于 build 和一个用于 单元测试,在 Maven 项目中。
这两个阶段可以用以下命令来概括:
- [构建]
mvn -s ci/settings.xml test-compile - [unit_tests]
mvn -s ci/settings.xml verify
在本地机器上运行它们时,第一个打印:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 133 source files to <mydir>
而第二个,鉴于项目已经建成,打印:
[INFO] Nothing to compile - all classes are up to date
这也是 GitLab 上的预期行为。
然而,在 GitLab 上发生的事情是,单元测试 阶段打印的内容与构建阶段完全相同,这意味着它没有正确使用我在之前导出的工件阶段。
这是构建工作:
build:
stage: build
image: maven:3.6-jdk-11
script:
- 'mvn -s ci/settings.xml test-compile'
except:
- tags
artifacts:
paths:
- target/
此作业以以下日志结束:
Uploading artifacts...
target/: found 226 matching files and directories
Uploading artifacts as "archive" to coordinator... ok id=1964 responseStatus=201 Created token=qwYzjEeM
表示target文件夹已正确上传。
这是单元测试的工作:
junit:
stage: unit_tests
script:
- 'mvn -s ci/settings.xml verify'
artifacts:
reports:
junit:
- target/surefire-reports/TEST-*.xml
此作业从以下日志开始:
Downloading artifacts for build (1964)...
Downloading artifacts from coordinator... ok id=1964 responseStatus=200 OK token=qwYzjEeM
表示 target 文件夹已正确接收(我还添加了 ls -la target 以查看文件是否存在并且它们看起来是否正确)。
鉴于工件似乎已正确上传/下载,为什么单元测试作业要重建整个项目?
【问题讨论】:
-
我不知道为什么这个gitlab目录移动失败,但是你为什么要这样做呢?为什么不直接运行
verify? -
这是我继承的一个管道,我无法更改它的步骤,因为很多项目都依赖于这个模板。此外,在 JUnit 之后还有更多的 maven 步骤,它们会遇到与这个完全相同的问题。