Programming

Github actions share workspaceartifacts between jobs

19 September 2026 · 9 min read

Github actions share workspaceartifacts between jobs

GitHub Actions have revolutionized the way developers automate their software workflows. A crucial aspect of efficient workflow design is the ability to share workspace/artifacts between jobs. Without this capability, each job would operate in isolation, requiring redundant tasks and hindering the seamless flow of data. This blog post explores how to effectively leverage GitHub Actions’ features to share data between jobs, optimizing your CI/CD pipelines and accelerating your development cycles. We will delve into the practical methods, best practices, and common pitfalls to avoid when implementing artifact sharing in your workflows. Understanding these concepts empowers you to build more robust, efficient, and maintainable automation processes, ultimately leading to faster deployments and higher-quality software.

Understanding GitHub Actions Workspaces and Artifacts

GitHub Actions provides a powerful environment for automating software development workflows. Each job within a workflow executes in its own virtual environment, known as a workspace. This workspace contains the files and directories necessary for the job to perform its tasks. However, by default, each job’s workspace is isolated. To enable communication and data transfer between jobs, we need to understand the concept of artifacts. Artifacts are files or directories that are uploaded from one job and can be downloaded and used by subsequent jobs within the same workflow run. Think of them as the bridge that connects different stages of your CI/CD pipeline.

Effectively managing artifacts is critical for optimizing workflow performance. For instance, consider a workflow that builds a software application. The first job might compile the code, generating executable files and libraries. Instead of recompiling the code in subsequent jobs (e.g., for testing or deployment), we can upload the compiled artifacts. This saves significant time and resources. According to GitHub’s documentation [ GitHub Artifacts Documentation ], artifact storage is automatically managed, but it’s important to understand the usage limits to avoid unexpected costs or workflow failures. Proper planning and artifact management are key to unlocking the full potential of GitHub Actions.

The ability to share workspace/artifacts enables complex workflows that involve multiple stages like building, testing, and deploying software. It allows for a modular approach, where each job focuses on a specific task, contributing to the overall goal of the workflow. Without this capability, developers would need to resort to cumbersome workarounds, such as committing intermediate results to the repository or relying on external storage services, adding unnecessary complexity and potential points of failure. This article will equip you with the knowledge to efficiently manage and share workspace/artifacts, enhancing the performance and reliability of your GitHub Actions workflows.

Sharing Artifacts Between Jobs: A Practical Guide

Sharing artifacts between jobs in GitHub Actions involves two primary steps: uploading artifacts in one job and downloading them in subsequent jobs. GitHub provides dedicated actions, actions/upload-artifact and actions/download-artifact, to simplify this process. The upload-artifact action allows you to specify the files or directories to be uploaded as artifacts, while the download-artifact action retrieves these artifacts and makes them available in the workspace of the downstream job. Here’s a detailed guide:

  1. Upload Artifact: Use the actions/upload-artifact action in the job that generates the artifacts. You need to specify the name of the artifact and the path to the files or directories you want to upload. For example: uses: actions/upload-artifact@v3 with: name: my-artifact path: ./build
  2. Download Artifact: In the subsequent job that needs to use the artifacts, use the actions/download-artifact action. Specify the name of the artifact to download. If no name is specified, all artifacts from the workflow run will be downloaded. You can also specify the path where the artifacts should be extracted. For example: uses: actions/download-artifact@v3 with: name: my-artifact path: ./artifacts
  3. Access Artifacts: Once the artifacts are downloaded, they are available in the specified path within the job’s workspace. You can then use these artifacts in your subsequent steps.

Consider a real-world scenario where you’re building a JavaScript application. One job might be responsible for running linters and code formatters. Another job could then build the application using npm run build. To avoid running the build process multiple times, the build output (e.g., the dist directory) can be uploaded as an artifact. The subsequent job, which deploys the application, can then download this artifact and deploy it directly, saving time and resources. This is a common practice to optimize CI/CD pipelines.

It’s crucial to choose meaningful artifact names to avoid confusion, especially in complex workflows with multiple artifacts. Additionally, consider the size of your artifacts. Large artifacts can increase workflow execution time and storage costs. Optimize your build process to minimize the size of the artifacts you upload. Compressing artifacts before uploading can also help reduce storage space and transfer time. Remember to delete artifacts that are no longer needed to avoid exceeding storage limits.

Best Practices for Artifact Management in GitHub Actions

Effective artifact management is crucial for maintaining efficient and reliable GitHub Actions workflows. Here are some best practices to consider:

  • Minimize Artifact Size: Only include necessary files in your artifacts. Exclude unnecessary files like temporary files, build logs (unless needed), and development dependencies. Compressing artifacts can further reduce their size.
  • Use Meaningful Artifact Names: Choose descriptive and consistent names for your artifacts to easily identify them in subsequent jobs. This improves readability and maintainability of your workflows.

One critical aspect is managing artifact retention. By default, GitHub Actions retains artifacts for 90 days. You can customize this retention period in your repository settings to better suit your needs. For example, you might want to retain artifacts for longer periods for debugging purposes or compliance requirements. Be mindful of storage costs associated with longer retention periods [ GitHub Packages Pricing ]. Regularly review and adjust your artifact retention policy to optimize storage usage and minimize costs.

Another important consideration is security. Artifacts can contain sensitive information, such as API keys or credentials. Avoid storing sensitive data directly in artifacts. Instead, use GitHub Secrets to securely manage sensitive information and inject them into your workflow at runtime. When downloading artifacts, verify their integrity to ensure they haven’t been tampered with. You can use checksums or digital signatures to validate the authenticity of artifacts. Implement robust security measures to protect your artifacts and prevent unauthorized access.

Featured Snippet Optimization: The actions/upload-artifact and actions/download-artifact actions are the core components for sharing data between jobs. To upload, specify the name and path: actions/upload-artifact@v3 with: name: my-artifact path: ./build. To download, reference the name and desired extraction path: actions/download-artifact@v3 with: name: my-artifact path: ./artifacts. This enables seamless data transfer for efficient CI/CD pipelines.

Advanced Techniques for Sharing Data

Beyond basic artifact sharing, GitHub Actions offers more advanced techniques for managing data between jobs. One such technique involves using the GITHUB_ENV environment variable to pass small amounts of data between jobs. This approach is suitable for sharing simple values, such as build numbers, commit hashes, or configuration settings. However, it’s not recommended for sharing large files or complex data structures.

To use GITHUB_ENV, you can write values to this environment variable in one job and then access them in subsequent jobs. For example: echo "BUILD_NUMBER=$(date +%s)" >> $GITHUB_ENV In a subsequent job, you can access the BUILD_NUMBER environment variable using $BUILD_NUMBER. This method is straightforward for simple data transfers but has limitations in terms of data size and complexity. For larger or more complex data, artifacts are a better choice. It’s important to understand the limitations and choose the appropriate method based on the specific requirements of your workflow.

  • Leverage artifact compression to reduce storage costs.
  • Implement robust security measures to protect sensitive data in artifacts.

Another advanced technique involves using external storage services, such as AWS S3 or Azure Blob Storage, to store and share artifacts. This approach can be useful for handling very large artifacts or for sharing artifacts across multiple workflows or repositories. It requires configuring the external storage service and using appropriate actions or scripts to upload and download artifacts. Services like AWS S3 provide tools to manage versioning [ AWS S3 Versioning ], ensuring that the correct artifact versions are used throughout your workflow.

Infographic here
FAQ: Sharing Workspace/Artifacts in GitHub Actions --------------------------------------------------
**Q: What is the maximum artifact size in GitHub Actions?**
A: The maximum artifact size is 2GB per artifact and 10GB per repository.
**Q: How long are artifacts stored in GitHub Actions?**
A: By default, artifacts are stored for 90 days. You can configure this retention period in your repository settings.
**Q: Can I share artifacts between different workflows?**
A: No, artifacts are specific to a workflow run and cannot be directly shared between different workflows. Consider using external storage for cross-workflow artifact sharing.
**Q: What happens if an artifact with the same name is uploaded multiple times?**
A: Only the last uploaded artifact with that name will be available.
Sharing workspace and artifacts between jobs is a cornerstone of efficient GitHub Actions workflows. By mastering the techniques discussed in this guide, you can significantly optimize your CI/CD pipelines, reduce redundancy, and accelerate your software development process. Experiment with different approaches, monitor your workflow performance, and continuously refine your artifact management strategies to achieve the best results. Now that you have this knowledge, go forth and build more streamlined and powerful workflows! Consider exploring other advanced topics like caching dependencies or using composite actions to further enhance your automation capabilities. **Question & Answer :** Trying to use Github's beta actions, I have two jobs, one that builds the code and then one that will deploy code. However, I can't seem to get the build artifact in deploy job.

My latest attempt is to manually set a container image with the same volumes for each job, according to docs this should be solution: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes

Sets an array of volumes for the container to use. You can use volumes to share data between services or other steps in a job. You can specify named Docker volumes, anonymous Docker volumes, or bind mounts on the host.

Workflow

name: CI on: push: branches: - master paths: - .github/workflows/server.yml - server/* jobs: build: runs-on: ubuntu-latest container: image: docker://node:10 volumes: - /workspace:/github/workspace steps: - uses: actions/checkout@master - run: yarn install working-directory: server - run: yarn build working-directory: server - run: yarn test working-directory: server - run: ls working-directory: server deploy: needs: build runs-on: ubuntu-latest container: image: docker://google/cloud-sdk:latest volumes: - /workspace:/github/workspace steps: - uses: actions/checkout@master - run: ls working-directory: server - run: gcloud --version 

The first job (build) has a build directory, but when the second job (deploy) runs it doesn’t and only contains the source code.

This project is a mono repo with code I’m trying to deploy being under path server hence all the working-directory flags.

You can use the Github Actions upload-artifact and download-artifact to share data between jobs. For example:

Job 1:

steps: - uses: actions/checkout@v4 - 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 

Job 2:

steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: name: my-artifact path: path/to/artifact - run: cat path/to/artifact/world.txt