Workflow Artifacts in GitHub Actions
1. Introduction
In GitHub Actions, workflow artifacts are files or directories created during the execution of a workflow. They serve as a way to persist data across jobs and can be utilized for debugging, testing, and deployment purposes.
2. What are Artifacts?
Artifacts are essentially the outputs of your workflows, which can include:
- Build outputs (e.g., compiled binaries)
- Test reports (e.g., JUnit XML files)
- Logs and other debugging information
Artifacts can be downloaded from the workflow run page and can be stored for later retrieval.
3. How to Use Artifacts
3.1 Uploading Artifacts
You can upload artifacts during a workflow run using the actions/upload-artifact
action. Here's an example:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: |
mkdir output
echo "Hello, World!" > output/hello.txt
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: my-artifact
path: output/hello.txt
3.2 Downloading Artifacts
To download artifacts in another job, use the actions/download-artifact
action:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v2
with:
name: my-artifact
- name: Use Artifact
run: cat hello.txt
4. Best Practices
- Keep artifact names descriptive for easier identification.
- Use versioning in your artifact names to avoid conflicts.
- Regularly clean up old artifacts to save storage space.
5. FAQ
What is the maximum size for an artifact?
The maximum size for a single artifact is 2 GB, and the total storage limit for artifacts per repository is 5 GB.
Can I access artifacts from previous workflow runs?
Yes, you can access artifacts from previous workflow runs as long as they haven't been deleted.