How do I use the artifacts section in a pipeline as code?

Modified on Wed, 21 Jun 2023 at 04:31 PM

The artifacts section in a pipeline as code allows you to define and upload files or directories generated during your pipeline jobs, making them available for download or use in subsequent stages or jobs. Artifacts are commonly used to store build outputs, test reports, coverage results, or any other files that you want to persist and access later in your pipeline.

To use the artifacts section in your pipeline as code, follow these steps:

Define the artifacts you want to store in your pipeline jobs. Artifacts can be individual files or entire directories. Each artifact definition consists of a path to the file or directory and an optional name.

Add the artifacts section to your pipeline configuration, and specify the artifacts using the key-value syntax. Here's an example:

    - build/reports/
    - app.jar

In the above example, two artifacts are defined: build/reports/ directory and app.jar file. These artifacts will be stored and made available for download.

The artifacts are automatically uploaded at the end of the job. You can access them through the GitLab user interface or use them in subsequent stages or jobs.

To download artifacts in another job or stage, you can use the dependencies keyword along with the artifacts keyword. For example:

    - echo "Performing some tasks..."
      - build/reports/

    - echo "Running downstream job..."
    - my_job

In this example, my_downstream_job has a dependency on my_job. The artifacts generated by my_job will be downloaded and available for use in my_downstream_job. You can access the files in the specified paths from the artifacts.

The artifacts section provides a convenient way to persist and share files or directories between jobs within your pipeline. This promotes modularity and facilitates the flow of data and outputs across different stages or jobs.

Note that artifacts can be controlled further with options like expiration time, artifacts reports, and artifacts download policies. Make sure to refer to the GitLab documentation for more details on these advanced configurations.

By utilizing the artifacts section in your pipeline as code, you can easily manage and share important files or directories generated during your pipeline execution. This helps in troubleshooting, collaboration, and analysis of pipeline results.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article