我正在寻找一种在 gitlab 中取消作业后清理跑步者的方法。
原因是我们经常不得不取消正在运行的作业,因为运行器有时会卡在测试管道中,我可以想象其他几种情况,您可能想要取消作业并在之后运行清理脚本。
我正在寻找类似 after_script
的东西,但只是在工作被取消的情况下。
我检查了 gitlab keyword reference,但找不到我需要的东西。
我的 gitlab-ci.yaml
的以下部分显示了我希望在取消作业时通过调用 docker-compose down
优雅地取消的测试阶段。
我使用的是单个 gitlab-runner。 另外我不使用dind。
test_stage:
stage: test
only:
- master
- tags
- merge_requests
image: registry.gitlab.com/xxxxxxxxxxxxxxxxxxx
variables:
HEADLESS: "true"
script:
- docker login -u="xxxx" -p="${QUAY_IO_PASSWORD}" quay.io
- npm install
- npm run test
- npm install wait-on
- cd example
- docker-compose up --force-recreate --abort-on-container-exit --build traefik frontend &
- cd ..
- apt install -y iproute2
- export DOCKER_HOST_IP=$( /sbin/ip route|awk '/default/ { print $3 }' )
- echo "Waiting for ${DOCKER_HOST_IP}/xxxt"
- ./node_modules/.bin/wait-on "http://${DOCKER_HOST_IP}/xxx" && export BASE_URL=http://${DOCKER_HOST_IP} && npx codeceptjs run-workers 2
- cd example
- docker-compose down
after_script:
- cd example && docker-compose down
artifacts:
when: always
paths:
- /builds/project/tests/output/
retry:
max: 2
when: always
tags: [custom-runner]
[1]: https://docs.gitlab.com/ee/ci/yaml/