{"meta":{"title":"Store and share data with workflow artifacts","intro":"Use artifacts to share data between jobs in a workflow and store data once that workflow has completed.","product":"GitHub Actions","breadcrumbs":[{"href":"/en/actions","title":"GitHub Actions"},{"href":"/en/actions/tutorials","title":"Tutorials"},{"href":"/en/actions/tutorials/store-and-share-data","title":"Store and share data"}],"documentType":"article"},"body":"# Store and share data with workflow artifacts\n\nUse artifacts to share data between jobs in a workflow and store data once that workflow has completed.\n\n## Prerequisites\n\nBefore you can complete this tutorial, you need to understand workflow artifacts. See [Workflow artifacts](/en/actions/concepts/workflows-and-actions/workflow-artifacts).\n\n## Uploading build and test artifacts\n\nThe output of building and testing your code often produces files you can use to debug test failures and production code that you can deploy. You can configure a workflow to build and test the code pushed to your repository and report a success or failure status. You can upload the build and test output to use for deployments, debugging failed tests or crashes, and viewing test suite coverage.\n\nYou can use the `upload-artifact` action to upload artifacts. When uploading an artifact, you can specify a single file or directory, or multiple files or directories. You can also exclude certain files or directories, and use wildcard patterns. We recommend that you provide a name for an artifact, but if no name is provided then `artifact` will be used as the default name. For more information on syntax, see the [actions/upload-artifact](https://github.com/actions/upload-artifact) action.\n\n### Example\n\nFor example, your repository or a web application might contain SASS and TypeScript files that you must convert to CSS and JavaScript. Assuming your build configuration outputs the compiled files in the `dist` directory, you would deploy the files in the `dist` directory to your web application server if all tests completed successfully.\n\n```text\n|-- hello-world (repository)\n|   └── dist\n|   └── tests\n|   └── src\n|       └── sass/app.scss\n|       └── app.ts\n|   └── output\n|       └── test\n|\n```\n\nThis example shows you how to create a workflow for a Node.js project that builds the code in the `src` directory and runs the tests in the `tests` directory. You can assume that running `npm test` produces a code coverage report named `code-coverage.html` stored in the `output/test/` directory.\n\nThe workflow uploads the production artifacts in the `dist` directory, but excludes any markdown files. It also uploads the `code-coverage.html` report as another artifact.\n\n```yaml copy\nname: Node CI\n\non: [push]\n\njobs:\n  build_and_test:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout repository\n        uses: actions/checkout@v6\n      - name: npm install, build, and test\n        run: |\n          npm install\n          npm run build --if-present\n          npm test\n      - name: Archive production artifacts\n        uses: actions/upload-artifact@v4\n        with:\n          name: dist-without-markdown\n          path: |\n            dist\n            !dist/**/*.md\n      - name: Archive code coverage results\n        uses: actions/upload-artifact@v4\n        with:\n          name: code-coverage-report\n          path: output/test/code-coverage.html\n```\n\n## Configuring a custom artifact retention period\n\nYou can define a custom retention period for individual artifacts created by a workflow. When using a workflow to create a new artifact, you can use `retention-days` with the `upload-artifact` action. This example demonstrates how to set a custom retention period of 5 days for the artifact named `my-artifact`:\n\n```yaml copy\n  - name: 'Upload Artifact'\n    uses: actions/upload-artifact@v4\n    with:\n      name: my-artifact\n      path: my_file.txt\n      retention-days: 5\n```\n\nThe `retention-days` value cannot exceed the retention limit set by the repository, organization, or enterprise.\n\n## Downloading artifacts during a workflow run\n\nYou can use the [`actions/download-artifact`](https://github.com/actions/download-artifact) action to download previously uploaded artifacts during a workflow run.\n\n> \\[!NOTE]\n> If you want to download artifacts from a different workflow or workflow run, you need to supply a token and run identifier. See [Download Artifacts from other Workflow Runs or Repositories](https://github.com/actions/download-artifact?tab=readme-ov-file#download-artifacts-from-other-workflow-runs-or-repositories) in the documentation for the `download-artifact` action.\n\nSpecify an artifact's name to download an individual artifact. If you uploaded an artifact without specifying a name, the default name is `artifact`.\n\n```yaml\n- name: Download a single artifact\n  uses: actions/download-artifact@v5\n  with:\n    name: my-artifact\n```\n\nYou can also download all artifacts in a workflow run by not specifying a name. This can be useful if you are working with lots of artifacts.\n\n```yaml\n- name: Download all workflow run artifacts\n  uses: actions/download-artifact@v5\n```\n\nIf you download all workflow run's artifacts, a directory for each artifact is created using its name.\n\nFor more information on syntax, see the [actions/download-artifact](https://github.com/actions/download-artifact) action.\n\n## Passing data between jobs in a workflow\n\nYou can use the `upload-artifact` and `download-artifact` actions to share data between jobs in a workflow. This example workflow illustrates how to pass data between jobs in the same workflow. For more information, see the [actions/upload-artifact](https://github.com/actions/upload-artifact) and [download-artifact](https://github.com/actions/download-artifact) actions.\n\nJobs that are dependent on a previous job's artifacts must wait for the dependent job to complete successfully. This workflow uses the `needs` keyword to ensure that `job_1`, `job_2`, and `job_3` run sequentially. For example, `job_2` requires `job_1` using the `needs: job_1` syntax.\n\nJob 1 performs these steps:\n\n* Performs a math calculation and saves the result to a text file called `math-homework.txt`.\n* Uses the `upload-artifact` action to upload the `math-homework.txt` file with the artifact name `homework_pre`.\n\nJob 2 uses the result in the previous job:\n\n* Downloads the `homework_pre` artifact uploaded in the previous job. By default, the `download-artifact` action downloads artifacts to the workspace directory that the step is executing in. You can use the `path` input parameter to specify a different download directory.\n* Reads the value in the `math-homework.txt` file, performs a math calculation, and saves the result to `math-homework.txt` again, overwriting its contents.\n* Uploads the `math-homework.txt` file. As artifacts are considered immutable in `v4`, the artifact is passed a different input, `homework_final`, as a name.\n\nJob 3 displays the result uploaded in the previous job:\n\n* Downloads the `homework_final` artifact from Job 2.\n* Prints the result of the math equation to the log.\n\nThe full math operation performed in this workflow example is `(3 + 7) x 9 = 90`.\n\n```yaml copy\nname: Share data between jobs\n\non: [push]\n\njobs:\n  job_1:\n    name: Add 3 and 7\n    runs-on: ubuntu-latest\n    steps:\n      - shell: bash\n        run: |\n          expr 3 + 7 > math-homework.txt\n      - name: Upload math result for job 1\n        uses: actions/upload-artifact@v4\n        with:\n          name: homework_pre\n          path: math-homework.txt\n\n  job_2:\n    name: Multiply by 9\n    needs: job_1\n    runs-on: windows-latest\n    steps:\n      - name: Download math result for job 1\n        uses: actions/download-artifact@v5\n        with:\n          name: homework_pre\n      - shell: bash\n        run: |\n          value=`cat math-homework.txt`\n          expr $value \\* 9 > math-homework.txt\n      - name: Upload math result for job 2\n        uses: actions/upload-artifact@v4\n        with:\n          name: homework_final\n          path: math-homework.txt\n\n  job_3:\n    name: Display results\n    needs: job_2\n    runs-on: macOS-latest\n    steps:\n      - name: Download math result for job 2\n        uses: actions/download-artifact@v5\n        with:\n          name: homework_final\n      - name: Print the final result\n        shell: bash\n        run: |\n          value=`cat math-homework.txt`\n          echo The result is $value\n```\n\nThe workflow run will archive any artifacts that it generated. For more information on downloading archived artifacts, see [Downloading workflow artifacts](/en/actions/managing-workflow-runs/downloading-workflow-artifacts).\n\n## Validating artifacts\n\nEvery time the upload-artifact action is used it returns an output called `digest`. This is a SHA256 digest of the Artifact you uploaded during a workflow run.\n\nWhen the download-artifact action is then used to download that artifact, it automatically calculates the digest for that downloaded artifact and validates that it matches the output from the upload-artifact step.\n\nIf the digest does not match, the run will display a warning in the UI and in the job logs.\n\nTo view the SHA256 digest, open the logs for the upload-artifact job or check in the Artifact output that appears in the workflow run UI."}