Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
docker在gitlab ci中等待不';工作不会失败_Docker_Sh_Gitlab Ci - Fatal编程技术网

docker在gitlab ci中等待不';工作不会失败

docker在gitlab ci中等待不';工作不会失败,docker,sh,gitlab-ci,Docker,Sh,Gitlab Ci,我在gitlab ci中的docker中使用docker来运行测试环境并在其中运行测试 为了等待所有测试完成,我使用docker wait tests: image: docker:19-git stage: tests script: - docker-compose -f docker-compose/my_test_env.yml up -d #setting up env - docker-compose -f docker-compose

我在gitlab ci中的docker中使用docker来运行测试环境并在其中运行测试

为了等待所有测试完成,我使用docker wait

tests:
    image: docker:19-git
    stage: tests
    script:
      - docker-compose -f docker-compose/my_test_env.yml up -d #setting up env
      - docker-compose -f docker-compose/tests.yml up -d #running tests
      - docker wait docker-compose-services_tests_1
如果测试出现一些问题,我需要使作业失败,但是(
docker wait docker-compose-services\u tests\u 1
)打印容器退出代码,返回此退出代码被视为成功操作,因此作业被视为通过<代码>docker wait没有不打印退出代码的选项

因此,我需要一些sh(不是bash)脚本来运行
docker wait
,如果容器返回非0退出代码(使作业失败),则使用非0退出代码退出


正确的方法是什么?

这里有两个选项

  • 删除第二个命令
    docker compose-f docker compose/tests.yml up中的
    -d
    ,这样做不需要使用第三步

  • 如果确实要运行compose dettached,只需添加捕获docker compose日志输出的脚本,并根据结果执行操作,退出0或1


  • 谢谢但这部分解决了我的问题。如果测试失败,docker将退出,退出时代码为
    ,退出时代码为8
    。如果测试通过,docker退出,代码为
    退出,代码为0
    。但gitlab ci作业在这两种情况下都取得了成功。但我需要它在
    退出时失败,代码为8