GitHub Actions Certification
GitHub Actions Core Concepts
Storing workflow data as artifacts
Sharing data files across jobs in a multi-job GitHub Actions workflow is easy with the upload and download artifact actions. In this guide, you'll learn how to create a simple ASCII art file in one job, upload it as an artifact, then download and use it in subsequent test and deploy jobs.
Note
This example uses the Ubuntu runner and the cowsay utility to generate a dragon.txt
file. You can adapt it to any file or command.
1. Initial Workflow Structure
Below is a basic workflow that generates a dragon.txt
file but does not yet share it between jobs:
name: Generate ASCII Artwork
on:
push:
jobs:
build_job_1:
runs-on: ubuntu-latest
steps:
- name: Install Cowsay Program
run: sudo apt-get install cowsay -y
- name: Execute Cowsay
run: cowsay -f dragon "Run for cover, I am a DRAGON....RAWR" >> dragon.txt
test_job_2:
# ...
deploy_job_3:
# ...
To pass files from build_job_1
to downstream jobs, use the actions/upload-artifact and actions/download-artifact actions.
2. Uploading Artifacts
Use actions/upload-artifact@v3
to upload files or directories as build artifacts. Here’s the minimal syntax:
steps:
- uses: actions/checkout@v3
- run: mkdir -p path/to/artifact
- run: echo hello > path/to/artifact/world.txt
- uses: actions/upload-artifact@v3
with:
name: my-artifact
path: path/to/artifact/world.txt
Parameter | Description |
---|---|
name | A unique identifier for the artifact |
path | File or directory to upload |
3. Downloading Artifacts
In downstream jobs, invoke actions/download-artifact@v3
to retrieve the artifact:
steps:
- uses: actions/download-artifact@v3
with:
name: my-artifact
path: path/to/artifact
4. Integrate Upload in the Build Job
Modify build_job_1
to upload the generated dragon.txt
:
name: Generate ASCII Artwork
on:
push:
jobs:
build_job_1:
runs-on: ubuntu-latest
steps:
- name: Install Cowsay Program
run: sudo apt-get install cowsay -y
- name: Execute Cowsay
run: cowsay -f dragon "Run for cover, I am a DRAGON....RAWR" >> dragon.txt
- name: Upload Dragon text file
uses: actions/upload-artifact@v3
with:
name: dragon-text-file
path: dragon.txt
5. Download in the Test Job
Ensure test_job_2
depends on build_job_1
and downloads the artifact before running assertions:
test_job_2:
needs: build_job_1
runs-on: ubuntu-latest
steps:
- name: Download Dragon text file
uses: actions/download-artifact@v3
with:
name: dragon-text-file
- name: Verify Content
run: grep -i "dragon" dragon.txt
6. Download in the Deploy Job
Similarly, pull the artifact in deploy_job_3
to read and then deploy:
deploy_job_3:
needs: test_job_2
runs-on: ubuntu-latest
steps:
- name: Download Dragon text file
uses: actions/download-artifact@v3
with:
name: dragon-text-file
- name: Display File
run: cat dragon.txt
- name: Deploy
run: echo "Deploying ......"
7. Workflow in Action
When you push these changes, GitHub Actions uploads and downloads the artifact across jobs.
Once all steps are configured correctly, the workflow completes successfully and the artifact persists in the workflow summary.
Sample Download Log
Run actions/download-artifact@v3
Starting download for dragon-text-file
Directory structure has been setup for the artifact
Total number of files that will be downloaded: 1
Artifact dragon-text-file was downloaded to /home/runner/work/actions-1/actions-1
Artifact download has finished successfully
Run cat dragon.txt
Run for cover, i am a DRAGON... RAWR
8. Artifact Retention Policy
By default, uploaded artifacts are retained for 90 days. To adjust this setting:
- Go to your repository’s Settings → Actions → Artifact and log retention.
- Update the retention period as needed.
Setting | Default | Location |
---|---|---|
Artifact retention period | 90 days | Repository settings under Actions |
Warning
Increasing retention beyond 90 days may count against your GitHub storage quota.
References
- actions/upload-artifact
- actions/download-artifact
- GitHub Actions Documentation
- Managing retention settings
Watch Video
Watch video content