DEV Community

Thiago (Zozô) Ozores
Thiago (Zozô) Ozores

Posted on • Edited on

5 2

Github Actions: Sharing artifacts between jobs

This will be a quick tip.

Some days ago, configuring a pipeline inside Github Actions I had the need to use a file generated by a job in another job, that are using distinct OS.

It's pretty straight forward do that, the only thing that you need is the upload-artifact and the download-artifact actions

Here is an example:

job1:

  runs-on: ubuntu-latest
  steps:
  - uses: actions/checkout@v1

  - run: mkdir -p dist

  - run: echo hello > dist/world.txt

  - uses: actions/upload-artifact@master
    with:
      name: hello-world-artifact
      path: dist/world.txt

job2:
  runs-on: macos-latest

  steps:
  - run: mkdir -p dist

  - uses: actions/download-artifact@master
    with:
      name: hello-world-artifact
      path: dist/world.txt

  - run: cat dist/world.txt
Enter fullscreen mode Exit fullscreen mode

Source code and documentation for the actions:

BONUS TIP
I had the need to fetch a file from the Github Releases as well and to do that I used the third-party action dsaltares/fetch-gh-release-asset@master, but the drawback is that action only runs on Linux (because of that I have to copy an artifact from one job to another one ;-) )

Here is an example:

uses: dsaltares/fetch-gh-release-asset@master
with:
  repo: "your-user/your-repo"
  version: "latest"
  file: "package.zip"
  target: "dist/package.zip"
  token: ${{ secrets.YOUR_TOKEN }} # If your repo is private, you need to fill with the personal access token
Enter fullscreen mode Exit fullscreen mode

Source code and documentation for the dsaltares/fetch-gh-release-asset action

That's all folks! Thank you and stay in tune for more tips.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay