Github 操作在作业之间共享工作区/工件? [英] Github actions share workspace/artifacts between jobs?
问题描述
尝试使用 Github 的 beta 操作,我有两项工作,一项是构建代码,另一项是部署代码.但是,我似乎无法在部署作业中获得构建工件.
Trying to use Github's beta actions, I have two jobs, one that builds the code and then one that will deploy code. However, I can't seem to get the build artifact in deploy job.
我最近的尝试是为每个作业手动设置一个具有相同卷的容器映像,根据文档,这应该是解决方案:https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes
My latest attempt is to manually set a container image with the same volumes for each job, according to docs this should be solution: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes
设置容器使用的卷数组.您可以使用卷在服务或作业中的其他步骤之间共享数据.您可以在主机上指定命名 Docker 卷、匿名 Docker 卷或绑定挂载.
Sets an array of volumes for the container to use. You can use volumes to share data between services or other steps in a job. You can specify named Docker volumes, anonymous Docker volumes, or bind mounts on the host.
工作流程
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
第一个作业 (build) 有一个构建目录,但是当第二个作业 (deploy) 运行时,它没有并且只包含源代码.
The first job (build) has a build directory, but when the second job (deploy) runs it doesn't and only contains the source code.
这个项目是一个单一存储库,我试图部署的代码位于路径 server
下,因此所有的 working-directory
标志.
This project is a mono repo with code I'm trying to deploy being under path server
hence all the working-directory
flags.
推荐答案
您可以使用 Github Actions upload-artifact 和 download-artifact 在作业之间共享数据.
You can use the Github Actions upload-artifact and download-artifact to share data between jobs.
在作业 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
还有job2:
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
这篇关于Github 操作在作业之间共享工作区/工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!