Skip to main content
← Back to workflows

How to Upload Artifacts with GitHub Actions?

actions/upload-artifact -
GitHub Action
v4.3.3
0
Contributors
Contributor - robherleyContributor - konradpabjan
Categories
CICUBE ANALYTICS INSIGHTS
Engineering Velocity: 25% Team Time Lost to CI Issues
View Platform →
3.5h
Time Saved/Dev/Week
40%
Faster Releases
Click for next insight
Usage
- uses: actions/upload-artifact@v4

upload-artifact logo

Upload Artifact

Allows us to upload files or directories, which we've designated as artifacts, directly from our GitHub Actions workflows.


What is the @actions/upload-artifact GitHub Action?

Basically, the @actions/upload-artifact package is a GitHub Action that allows us to upload files or directories, which we've designated as artifacts, directly from our GitHub Actions workflows. What makes it super handy is that once these artifacts are uploaded, they can be accessed from any subsequent jobs in the workflow or even from outside if needed.

Here’s how it enhances our workflow:

  • Efficiency in Sharing Work: We can compile code, run tests, and upload the results as an artifact all within our CI process. Later, other jobs can use these artifacts without redoing the compilation or tests.
  • Flexible Artifact Handling: It supports uploading single files, directories, or even sets of files based on wildcard patterns. This flexibility ensures we can precisely control what we store and share as artifacts.
  • Management of Artifacts: It manages how artifacts are stored, simplifying the retrieval process. Artifacts are available immediately after upload and can be downloaded directly from the GitHub UI or through the GitHub API.

Example Configurations:

  • Single File Upload: Upload a single file by specifying the file path directly.
  • Directory Upload: Upload an entire directory by providing the directory path.
  • Wildcard Upload: Use wildcard patterns to upload specific subsets of files.

How to Upload an Individual File

To upload a single file using GitHub Actions:

  1. Create the necessary directory structure using the mkdir command.
  2. Generate or place the file you want to upload in the created directory. For example, create a file called world.txt with the content "hello".
  3. Use the actions/upload-artifact@v4 action to upload the file. Specify the artifact name and the path to the file.
steps:
- run: mkdir -p path/to/artifact
- run: echo hello > path/to/artifact/world.txt
- uses: actions/upload-artifact@v4
with:
name: my-artifact
path: path/to/artifact/world.txt

How to Upload an Entire Directory

To upload an entire directory as an artifact:

  1. Use the actions/upload-artifact@v4 action and specify the directory path in the path input. Ensure the directory path ends with a slash to indicate it is a directory.
- uses: actions/upload-artifact@v4
with:
name: my-artifact
path: path/to/artifact/ # or path/to/artifact

How to Upload Using a Wildcard Pattern

To upload files matching a specific pattern:

  1. Use wildcards in the path input to specify which files to include in the upload. This example uploads all files that fit the specified wildcard pattern within the directory.
- uses: actions/upload-artifact@v4
with:
name: my-artifact
path: path/**/[abc]rtifac?/*

How to Upload Using Multiple Paths and Exclusions

To upload multiple files or directories while excluding certain files:

  1. List each path on a new line within the path input.
  2. Use the ! symbol to exclude files or directories that match the specified pattern.
- uses: actions/upload-artifact@v4
with:
name: my-artifact
path: |
path/output/bin/
path/output/test-results
!path/**/*.tmp

These instructions provide clear, step-by-step guidance on how to configure the GitHub Actions workflow to manage artifact uploads effectively.