我的“问题”是当我在远程 docker 机器上运行我的 ci 时,gitlab-runner 离开了在那里使用的容器而没有删除它们。另一件事是当您显示到卷文件夹时也会给出项目源。
有人可能有想法我可以如何更改它,容器和项目源将在 ci-pipeline 运行后被删除?
好的问候, cRUSH
stages:
- Build
- Testing
- Execute
- Publish
- CleanUp
build_cleanup:
only:
- master
stage: Build
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
testing_cleanup:
only:
- master
stage: Testing
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
excecute_cleanup:
only:
- master
stage: Execute
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
publish_cleanup:
only:
- master
stage: Publish
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
cleanup_jobs:
only:
- master
stage: CleanUp
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: always
这是我目前的配置。