Github actions share workspace/artifacts between jobs?

Labithiotis :

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.

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

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.

Workflow

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.

This project is a mono repo with code I'm trying to deploy being under path server hence all the working-directory flags.

Tyler Carberry :

You can use the Github Actions upload-artifact and download-artifact to share data between jobs.

In 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

And 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-artifact
https://github.com/actions/download-artifact

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Github Actions, how to share a calculated value between job steps?

Share a Net::IMAP connection between controller actions

Share result of a step between different jobs in CircleCi

Share Data between controller actions Rails

Share installed requirements between jobs

Is it possible to persist a WORKDIR between Actions in GitHub Actions?

How to pass variable between two successive GitHub Actions jobs?

github actions share workspace (yml config)

Retry failed jobs in github actions

difference between "run |" and multiple runs in github actions

Share files between azure pipeline Jobs

GitHub Actions: sharing/referencing jobs between workflows

Github Actions - No jobs defined in `jobs`

How can i share state between my flink jobs?

How to share files between jobs

How I create a job to run after all jobs in Github Actions

Share workflow artifacts between workflow runs / github actions using the API

GitHub - jobs : what is : use actions/checkout

How to pass an API token as output variable between jobs in GitHub Actions

Share actions between slices with Redux Toolkit

Difference between 'run:' and 'run: |' in GitHub Actions

how to run Github Actions Jobs in parallel using matrix?

Is it possible to share or reuse some job steps inside Github actions?

GitHub Actions won't start jobs wit job output in if statement

GitHub Actions Badges for multiple jobs in a single file

How can I show the three statuses of GitHub Actions jobs?

How to pass job level environment variable between jobs - Github Actions

Jobs getting skipped in GitHub Actions

Share generated GitHub Token within different jobs on GitHub actions