Get artifacts from previous GIT jobs

3.2k Views Asked by At

I have a 3 stages in pipeline, each job in all 3 stages are creating a xml data files. These jobs which runs in parallel.

enter image description here

I want to merge all xml data file in 4th stage. Below is my yml code

stages:
  - deploy
  - test
  - execute
  - artifact
script:
   - XYZ
artifacts:
  name: datafile.xml
paths:
  - data/

Problem: how i can collect all xmls from previous jobs to merge it? Files names are unique.

1

There are 1 best solutions below

0
Aleksey Tsalolikhin On

Here is a .gitlab-ci.yml file that collects artifacts into a final artifact (takes a file generated by earlier stages, and puts them all together).

The key is the needs attribute which takes the artifacts from the earlier jobs (with artifacts: true).

stages:
  - stage_one
  - stage_two
  - generate_content

apple:
  stage: stage_one
  script: echo apple > apple.txt
  artifacts:
    paths:
      - apple.txt


banana:
  stage: stage_two
  script: echo banana > banana.txt
  artifacts:
    paths:
      - banana.txt

put_it_all_together:
  stage: generate_content
  needs:
    - job: apple
      artifacts: true
    - job: banana
      artifacts: true
  script:
    - cat apple.txt banana.txt > fruit.txt
  artifacts:
    paths:
      - fruit.txt