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
第一个作业(构建)具有一个构建目录,但是当第二个作业(部署)运行时却没有并且仅包含源代码。
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 <下部署/ code>,因此所有
工作目录
标志。
推荐答案
您可以使用Github Actions上传工件和下载工件在作业之间共享数据。
You can use the Github Actions upload-artifact and download-artifact to share data between jobs.
在job1中:
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
https://github.com/actions/upload-人工制品
https://github.com/actions/download-artifact
这篇关于Github动作在作业之间共享工作空间/工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!