6

Due to disk space limitations I want to expire my artifacts within a few hours. Gitlab-CI supports this, by defining the time in expire_in.

This works perfectly, but I have a manual deploy step (click a button to start the deploy). The deploy basically rsyncs the webroot to the server. The problem is when the artifacts are expired (in this example after 3 hours). If you hit the manual deploy button, errors will be thrown because the webroot artifact no longer exists. The previous steps need to be rebuilt before deploy. All of this is perfectly understandable, but it's inconvenient to have to read through the error log to find out why the deploy failed.

I would like to disable the manual step (make the button unclickable), when the artifacts it depends on are no longer available. Is there any option to achieve this?

gitlab-ci.yaml

stages:
  - build frontend
  - build backend
  - deploy

before_script:
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - mkdir -p ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

npm build:
  stage: build frontend
  image: node:6
  script:
    - cd build
    - yarn install
    - npm run build:prod
  artifacts:
    paths:
      - profile/
    expire_in: 1 hour

drupal build:
  stage: build backend
  image: drupaldocker/drush:8
  dependencies:
    - npm build
  script:
    - sudo apt-get update
    - sudo apt-get install unzip
    - cd webroot
    - drush make drupal.make.yml -y
    - rm -r sites
  artifacts:
    paths:
      - webroot/
    expire_in: 3 hours

staging deploy:
  stage: deploy
  image: drupaldocker/drush:8
  dependencies:
    - drupal build
    - npm build
  script:
    - export SSH_ENV_DIR="master1/drupal"
    - bash bin/gitlab/deploy.sh
  when: manual
  environment:
    name: staging
dbrekelmans
  • 951
  • 8
  • 11
  • Your artifacts on manual jobs expire? Mine never do (and that's a bigger problem) https://gitlab.com/gitlab-org/gitlab/-/issues/373066 – Tofandel Sep 08 '22 at 19:37

2 Answers2

0

you should try with latest gitlab version it should display a reason now. (v11.2)

Danny
  • 1,603
  • 1
  • 15
  • 25
0

I don't believe there is any functionality like that currently. You could fill out a feature request issue here, but it likely won't get added for quite a while (if at all). There is another similar request in this issue that would have the job fail outright if the artifact isn't present, but it doesn't look like there's been much activity on it.

If you're a paying customer, it tends to get things moving a lot faster by requesting the feature with their support team.

However, you can mimic the functionality the issue above would implement by adding a check at the top of the script section (or before_script if the artifacts are extracted before that, can't recall when it's extracted) to check if the file/directory you're expecting exist. If they don't, fail with a message explaining the build step should be re-run. That could look something like this:

...
script:
  - [ -d required_dir ] || MISSING=true
  # or
  - [ -f required_file ] || MISSING=true
  - if [ $MISSING ]; then
     echo "Required artifact is missing. Please re-run step XYZ."
     exit 1
    fi
  - # continue as normal since artifact(s) exist
Adam Marshall
  • 6,369
  • 1
  • 29
  • 45