107

Github のベータ アクションを使用しようとして、2 つの仕事があります。1 つはコードをビルドし、もう 1 つはコードをデプロイします。ただし、デプロイ ジョブでビルド アーティファクトを取得できないようです。

私の最新の試みは、ドキュメントによると、各ジョブに同じボリュームのコンテナー イメージを手動で設定することです。 jobsjob_idcontainervolumes

コンテナーが使用するボリュームの配列を設定します。ボリュームを使用して、サービス間またはジョブ内の他のステップ間でデータを共有できます。名前付きの Docker ボリューム、匿名の Docker ボリューム、またはホスト上のバインド マウントを指定できます。

ワークフロー

name: CI
on:
  push:
    branches:
    - master
    paths:
    - .github/workflows/server.yml
    - server/*
jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: docker://node:10
      volumes:
      - /workspace:/github/workspace
    steps:
    - uses: actions/checkout@master
    - run: yarn install
      working-directory: server
    - run: yarn build
      working-directory: server
    - run: yarn test
      working-directory: server
    - run: ls
      working-directory: server
  deploy:
    needs: build
    runs-on: ubuntu-latest
    container:
      image: docker://google/cloud-sdk:latest
      volumes:
      - /workspace:/github/workspace
    steps:
      - uses: actions/checkout@master
      - run: ls
        working-directory: server
      - run: gcloud --version

最初のジョブ (ビルド) にはビルド ディレクトリがありますが、2 番目のジョブ (デプロイ) を実行すると、ビルド ディレクトリはなく、ソース コードのみが含まれます。

このプロジェクトは、パスの下に配置しようとしているコードを含むモノレポであるserverため、すべてのworking-directoryフラグがあります。

4

4 に答える 4

82

Github アクションの upload-artifact と download-artifact を使用して、ジョブ間でデータを共有できます。

ジョブ 1 で:

steps:
- uses: actions/checkout@v1

- run: mkdir -p path/to/artifact

- run: echo hello > path/to/artifact/world.txt

- uses: actions/upload-artifact@master
  with:
    name: my-artifact
    path: path/to/artifact

そしてジョブ2:

steps:
- uses: actions/checkout@master

- uses: actions/download-artifact@master
  with:
    name: my-artifact
    path: path/to/artifact
    
- run: cat path/to/artifact/world.txt

https://github.com/actions/upload-artifact
https://github.com/actions/download-artifact

于 2019-09-10T19:56:36.153 に答える