John Baltimore
John Baltimore

Reputation: 97

how to check if artifact exists gitlab

in gitlab I have a "job1" that sometimes does not start whatsoever due to various reason and I can't change that. When that job is skipped, then the artifacts for the job is not created.

My question is, is there a way for job2 to check if the artifact from job1 exists? It is not a question of whether or not we can fix job1 to make it always send the artifact, it is a question of how can I check if the "art.txt" file is there or not

Upvotes: 0

Views: 4341

Answers (1)

Mouson Chen
Mouson Chen

Reputation: 1234

if job1 create artifact art.txt fail, job1 status will fail. you can used dependencies, when job1 failure job2 will not start, maybe look like:

job1:
  stage: stage1
  script:
    - create art.txt
  artifact:
    paths:
      - art.txt

job2:
  stage: stage2
  script:
    - do something.
  dependencies:
    - job1

if job1 create artifact art.txt fail, job1 status will success. you can check art.txt status used shell script in job2 script section. look lik

job2:
  stage: stage2
  script:
    - |
      if [[ -f art.txt ]]; then 
        "is exist";
      else
        "is not exist";
        exit 1;
      fi;

  dependencies:
    - job1

Upvotes: 1

Related Questions