Run the script command before the branch is checked out in GitLab-CI

GitLab-CI executes a stop-environment script in dynamic environments after a branch is removed.This actually forces you to put all the teardown logic in .gitlab-ci.yml

instead of a script that only makes calls .gitlab-ci.yml

.

Does anyone know a workaround for this? I have a shell script that removes the deployment. This script is part of the repository and can also be called locally (i.e. not onli in a CI environment). I want GitLab-CI to call this script when the dynamic environment is removed , but obviously there isn't one when the branch is deleted. I also cannot put this script in artifacts as it is generated before build by the configure

script and contains secrets. It would be great if it could be done breaking the script before the branch is deleted.

Here's a relevant excerpt from .gitlab-ci.yml

deploy_dynamic_staging:
    stage: deploy
    variables:
        SERVICE_NAME: foo-service-$CI_BUILD_REF_SLUG
    script:
        - ./configure
        - make deploy.staging
    environment:
        name: staging/$CI_BUILD_REF_SLUG
        on_stop: stop_dynamic_staging
    except:
        - master

stop_dynamic_staging:
    stage: deploy
    variables:
        GIT_STRATEGY: none
    script:
        - make teardown # <- this fails
    when: manual
    environment:
        name: staging/$CI_BUILD_REF_SLUG
        action: stop

      

+3


source to share





All Articles