How to check if environment/devployment exists/successfull inside a job and decide to deploy/update it

Viewed 70

In the gitlab ce omnibus 14.10.2 instance, there is a project in which it is necessary to make a pipeline in gitlab-ci.yml that would check for the existence of dynamical environment deployments and if they are not there, then do nothing, and if they are, it would update them or manually deploy by a trigger from the webui.

My example:

#...
check-review:
  variables: 
    GIT_STRATEGY: none
  stage: dev/review/check
  only:
    - /^(feature|hotfix)\/(.*)/m
  dependencies: []
  allow_failure: true
  script:
    - curl -sLf ${CI_COMMIT_REF_SLUG}.domain.io --output /dev/null
  when: always

ansible/deploy:
  stage: dev/review
  only:
    - /^(feature|hotfix)\/(.*)/m
  except:
    - master
    - staging
  environment:
    name: $CI_COMMIT_REF_NAME
    url: https://${CI_COMMIT_REF_SLUG}.domain.io
    action: start
    on_stop: ansible/undeploy
  when: on_success
  dependencies:
    - vendor # build back
  script:
    - make deploy

ansible/undeploy:
  stage: dev/review
  variables: 
    GIT_STRATEGY: none
  environment:
    name: $CI_COMMIT_REF_NAME
    url: https://${CI_COMMIT_REF_SLUG}.domain.io
    action: stop
  when: manual
  needs:
    - job: ansible/deploy
  script:
    - make delete_dev_stand

This condition need because dev teams workinig on many branches and not everyone need to be deployed on dev envs, on the other hand with manual update only - on every update/fix code qa need to go gitlab webui & trigger job to deploy/update deployment in environments https://${CI_SERVER_HOST}/${CI_PROJECT_PATH}/-/environments/

Maybe I`ve miss something in gitlab-ci ref, only solution that I found was to make failure pipline on check stage/job but this not happy to see so many failed pipelines.

0 Answers
Related