Skip to content

Latest commit

 

History

History
100 lines (72 loc) · 3.15 KB

storing-artifacts.md

File metadata and controls

100 lines (72 loc) · 3.15 KB

Storing artifacts

When running multiple jobs, the VM you get for each job is completely new.

This means that the state of the repository is not persisted between jobs.

It is possible to store your state (and therfore also artifacts) in Github Actions.

An artifact could be the result of the build, in this case the compiled code.

This should not be mistaken for proper artifact management, or release management but it is useful for making the artifacts built by the pipeline available.

To deal with artifacts, a Github Actions Action can be used, which can be found on Github Marketplace.

To upload artifacts use the following syntax with actions/upload-artifact@v3 Link to documentation:

- name: Upload a Build Artifact
  uses: actions/upload-artifact@v3
  with:
    name: my-artifact
    path: path/to/artifact/

As artifacts can be uploaded it can also be downloaded from Github Actions with help of actions/download-artifact@v3 as:

- name: Download a single artifact
  uses: actions/download-artifact@v3
  with:
    name: my-artifact
    path: path/to/download/artifact/

Link to documentation

This information will be needed in next exercises.

💡

More information about storing artifacts Github has an excelent guide on how you can use persistant storage over periods of builds here: https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts

Exercise

Overview

We want to add a step that makes the repository including the compiled code available for other steps to use.

In order to achieve this we will simply save the state of the entire repository after running the build script.

Tasks

  • Add step named Upload Repo to the existing job, which will upload an artifact with the name code, with the path . to use the current directory.
    - name: Upload Repo
      uses: actions/upload-artifact@v3
      with: 
        name: code
        path: .

Solution

If you strugle and need to see the whole Solution you can extend the section below.

Solution
on: push
jobs:
  Build:
    runs-on: ubuntu-latest
    container: gradle:6-jdk11
    steps:
      - name: Clone-down
        uses: actions/checkout@v3       
      - name: Build application
        run: chmod +x ci/build-app.sh && ci/build-app.sh
      - name: Test
        run: chmod +x ci/unit-test-app.sh && ci/unit-test-app.sh
      - name: Upload Repo
        uses: actions/upload-artifact@v3
        with: 
          name: code
          path: .

Results

If all works out fine, your newest build should show something like, where you can find your uploaded artifact: Uploading artifact

Resources

https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts