我有一个 docker compose 项目。该代码不会在 docker 中编译并以代码 2 退出,但 GitHub 会传递该作业并标记为已完成。
Yml 文件:
name: Docker Build
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Docker build staging
run: |
docker compose -f docker-compose.yml up --build -d
deploy:
runs-on: [self-hosted, Linux, X64, staging]
needs: build
steps:
- name: Checkout the files
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- run: |
docker compose -f docker-compose.yml up --build -d
输出:
Failed to solve: executor failed running [/bin/sh -c npm run staging:start]: exit code: 2
#91 CANCELED
如果有人遇到此问题,则问题出在 bash 上。当您在 bash 脚本中启动 docker compose 时,操作无法检测到错误。相反,您可以直接在运行命令中键入脚本中的命令。
您可以将退出代码从图像传递到 GitHub 操作,抛出命令
docker compose -f docker-compose.yml up --build --exit-code-from {image name}