How to Upload Artifacts with GitHub Actions?
GitHub Actions is a powerful automation tool that enables developers to streamline workflows, automate testing, and deploy applications with ease. One useful feature of GitHub Actions is the ability to upload and download artifacts. Artifacts are files generated during a workflow run that you want to save for later use, such as test results, compiled binaries, or log files.
Why Upload Artifacts in GitHub Actions?
Artifacts allow you to preserve important workflow outputs, making them available for reference or further processing in subsequent workflow steps. Some common use cases for artifact uploads include:
- Storing test reports and logs for debugging failed builds.
- Saving build outputs (e.g., installation packages, compiled files) for later distribution.
- Sharing files between different jobs in a workflow.
Setting Up Artifact Uploads
To upload artifacts in GitHub Actions, you need to use the actions/upload-artifact action. This built-in action makes it simple to save files generated during your workflow execution.
Example Workflow with Artifact Upload
The following example demonstrates a basic workflow that runs tests and uploads the test report as an artifact:
name: Upload Artifact Example
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run tests
run: |
mkdir -p test-results
echo "Test report content" > test-results/report.txt
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: test-results
path: test-results/
In this workflow:
- The repository is checked out using actions/checkout@v4.
- A folder
test-results
is created, and a dummy test report is saved. - The report is uploaded using actions/upload-artifact@v4, making it accessible later.

Downloading Artifacts
Once an artifact is uploaded, you may want to download it in a different job. This can be done using the actions/download-artifact action.
Example of Using Uploaded Artifacts
The following workflow builds on the previous one by adding a second job to download and process the test report:
jobs:
process-results:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download test results
uses: actions/download-artifact@v4
with:
name: test-results
path: downloaded-results
- name: Display test results
run: cat downloaded-results/report.txt
Here, the workflow:
- Waits for the
build
job to complete. - Downloads the stored artifact into a
downloaded-results
directory. - Displays the content of the report file.
Customizing Artifact Uploads
You can customize artifact uploads with additional parameters:
- Retention Period: Define how long GitHub stores the artifact before automatically deleting it.
- Paths: Support wildcard patterns to include multiple files or folders.
For example, to store artifacts for 7 days and include all .log
files:
uses: actions/upload-artifact@v4
with:
name: logs
path: logs//*.log
retention-days: 7

Best Practices for Using Artifacts
To make the most of GitHub Actions artifact uploads, follow these best practices:
- Keep artifact sizes minimal: Avoid storing unnecessary files to reduce workflow execution time.
- Use descriptive artifact names: Helps in easily identifying purpose and contents.
- Set appropriate retention policies: Prevent old artifacts from piling up and consuming storage space.
- Secure sensitive information: Avoid uploading confidential data like API keys or credentials.
Conclusion
Uploading artifacts with GitHub Actions simplifies workflow management by allowing developers to store and reuse important files efficiently. Whether you need to retain build artifacts, test results, or logs, the actions/upload-artifact and actions/download-artifact actions provide a seamless way to handle these assets. By following best practices and optimizing artifact use, you can make your CI/CD pipelines more effective and streamlined.
Comments are closed, but trackbacks and pingbacks are open.