github - Github 操作在作业之间共享工作区/工件?
问题描述
尝试使用 Github 的 beta 操作时,我有两份工作,一份负责构建代码,另一份负责部署代码。但是,我似乎无法在部署工作中获得构建工件。
我最近的尝试是为每个作业手动设置具有相同卷的容器映像,根据文档,这应该是解决方案:https ://help.github.com/en/articles/workflow-syntax-for-github-actions#工作job_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
第一个作业 (build) 有一个 build 目录,但是当第二个作业 (deploy) 运行时它没有并且只包含源代码。
这个项目是一个单声道存储库,其中的代码我试图部署在路径下,server
因此所有的working-directory
标志。
解决方案
您可以使用 Github Actions 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
推荐阅读
- php - 在 PHP 中使用 sqlsrv 防止 SQL 注入
- node.js - 如何将 fetch 转换为 axios
- javascript - 如何禁用特定元素的上下文菜单?
- windows - 将文件从一个目录分组到另一个目录,文件名中具有特定模式
- java - JavaFX ScrollPane 不符合其约束
- javascript - Chrome 和 Firefox 中奇怪的控制台输出
- sql - 执行多个查询时,“psql -c”和“psql -f”有什么区别?
- css - firefox 使用“transform:rotate;”导致视觉伪影;
- azure - Terraform - 如何获取 azurerm 密钥保管库访问策略的应用服务对象 ID?
- android - 如何删除动态显示的 WebView 中的 div?(安卓)