Skip to content

DevOps Operations / Continuous integration · Step 6 of 7

Lesson: Build ArtifactsSwitch
← DevOps Operations

Delivery and containers

Build Artifacts

Save files produced by a workflow and pass them between jobs as artifacts.

A hosted runner is thrown away when its job ends, and its files go with it. An artifact is a file or folder that you ask CI to keep, such as a compiled program or a test report.

Uploading

yaml
      - run: |
          mkdir -p dist
          echo "version 1" > dist/app.txt
      - uses: actions/upload-artifact@v7
        with:
          name: app
          path: dist/
          retention-days: 7

name identifies the artifact within the run, and path says what to include. Artifacts expire. retention-days sets how long to keep this one, within the limits of your repository settings.

Passing files between jobs

Jobs do not share a disk, so a later job downloads the artifact:

yaml
  check:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: app
          path: dist
      - run: cat dist/app.txt
version 1

needs: build matters. Without it, check could start before the artifact exists.

This also gives you "build once, test and ship the same file". Rebuilding in every job can produce slightly different results.

Downloading to your computer

Use the run's page on GitHub, or the CLI:

bash
gh run download 1234567890 --name app --dir downloaded

Useful details

  • With upload-artifact v4 and later, two jobs cannot upload to the same artifact name in one run. In a matrix, include the matrix value in the name.
  • Hidden files are left out by default.
  • File permissions such as the executable bit are not preserved. Put files in a tar archive first if they matter.
  • Do not upload secrets, such as .env files or private keys. People with access to the repository may download artifacts.

An artifact is not the same as a cache. A cache speeds up later runs by reusing things like downloaded dependencies, which can be recreated. An artifact is an output you want to keep or inspect.

Test reports are worth keeping even when tests fail. Add if: always() to the upload step so that an earlier failure does not skip it. The official documentation lists storage limits, which depend on your plan.

Try it

Practise the permissions workaround locally:

bash
mkdir -p dist && printf '#!/bin/sh\necho hi\n' > dist/hi.sh
chmod +x dist/hi.sh
tar -czf dist.tar.gz dist
tar -tzvf dist.tar.gz

The listing shows the x bits stored in the archive. The search and archives lab has more tar practice.

Check your understanding

Build Artifacts

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.