gpt4 book ai didi

Github 操作在作业之间共享工作空间/工件?

转载 作者:行者123 更新时间:2023-12-03 06:10:28 32 4
gpt4 key购买 nike

尝试使用 Github 的 beta 操作,我有两项工作,一项负责构建代码,另一项负责部署代码。但是,我似乎无法在部署作业中获取构建工件。

我最新的尝试是为每个作业手动设置具有相同卷的容器镜像,根据文档,这应该是解决方案:https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes

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

第一个作业(构建)有一个构建目录,但是当第二个作业(部署)运行时它没有,并且仅包含源代码。

这个项目是一个单一存储库,其中的代码我试图在路径 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

关于Github 操作在作业之间共享工作空间/工件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57498605/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com