.yml文件如何区分成功和失败后的产物。

build-job:
  stage: build
  script:
    - pwd
    - source /etc/profile
    - cd WYAirLeakMainConsole
    - qmake
    - make >&../MakeOut.txt
    - mkdir ../WYAirLeak
    - cp -r Common/* ../WYAirLeak/
  artifacts:
      when: on_success
      paths:
        - WYAirLeak/
  artifacts:        
      when: on_failure
      paths:
        - MakeOut.txt
$ source /etc/profile
$ cd WYAirLeakMainConsole
$ qmake
$ make >&../MakeOut.txt
$ mkdir ../WYAirLeak
$ cp -r Common/* ../WYAirLeak/
Job succeeded

上面这里直接忽略了artifacts,没有输出产物。
可是有时,同样的yml文件,未做任何修改,又可以输出产物,情况如下。

$ source /etc/profile
$ cd WYAirLeakMainConsole
$ qmake
$ make >&../MakeOut.txt
$ mkdir ../WYAirLeak
$ cp -r Common/* ../WYAirLeak/
Uploading artifacts for successful job
00:02
Uploading artifacts...
Runtime platform                                    arch=amd64 os=linux pid=12945 revision=7f093137 version=15.2.0
WYAirLeak/: found 134 matching files and directories 
MakeOut.txt: found 1 matching files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created  id=112 responseStatus=201 Created token=kGyTEoUV
Job succeeded

究竟是什么原因呢?该如何输出构建成功和失败的产物呢?

补充一下,Gitlab版本:15.1

目前应该是不能在一个job中输出两个artifacts,你可以改成always,无论成功或失败都输出:

build-job:
  stage: build
  script:
    - pwd
    - source /etc/profile
    - cd WYAirLeakMainConsole
    - qmake
    - make >&../MakeOut.txt
    - mkdir ../WYAirLeak
    - cp -r Common/* ../WYAirLeak/
  artifacts:
      when: always
      paths:
        - WYAirLeak/
        - MakeOut.txt
1 个赞