Module 3 Lesson 3: Working with Artifacts
·DevOps

Module 3 Lesson 3: Working with Artifacts

Save your work. Learn how to use 'Artifacts' to pass files between stages (e.g., from Build to Test) and how to download them for manual review.

Module 3 Lesson 3: Working with Artifacts

Every Job in GitLab starts with a "Clean Slate." Files created in the build stage are DELETED before the test stage starts. To "Pass" files forward, you must use Artifacts.

1. What is an Artifact?

An artifact is a file or folder that is uploaded back to the GitLab server after a job finishes.

  • Subsequent stages will automatically download these files.
  • Users can download them from the GitLab website (e.g., download a .pdf report or a compiled .exe).

2. Defining Artifacts in YAML

build-app:
  stage: build
  script:
    - npm run build
  artifacts:
    # Which paths should we save?
    paths:
      - dist/
      - logs/*.log
    # How long should GitLab keep these files?
    expire_in: 1 week

3. Passing Data Between Stages

If test-job needs the dist/ folder created by build-app, it will find it automatically if they are in sequential stages.

  • GitLab handles the "Upload" and "Download" behind the scenes.

4. Why Use Artifacts?

  1. Auditing: If a user reports a bug in v1.2, you can go back to that pipeline and download the exact binary that was shipped.
  2. Reports: Automated tests often generate HTML reports. By setting them as artifacts, you can view them in your browser without leaving GitLab.
  3. Speed: You compile your app ONCE (in the build stage) and use that exact binary for all testing and deployment stages.

Exercise: The Artifact Relay

  1. Create a job create-file in the build stage.
  2. Script: echo "Hello Artifact" > info.txt.
  3. Add an artifacts block that saves info.txt.
  4. Create a second job read-file in the test stage.
  5. Script: cat info.txt.
  6. Run the pipeline. Does the second job find the file even though it's on a "Different" runner?
  7. Check the job's sidebar on GitLab. Do you see a button to "Download Artifacts"?

Summary

Artifacts are the "Memory" of your pipeline. Without them, your stages are isolated islands. With them, you can build a cohesive "Assembly Line" that transforms raw source code into a finished product.

Next Lesson: Speed it up: Caching dependencies.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn