vRA Code Stream – Preserving files and artifacts created in a CI Task
Tags: general, vmware, codestream, preserveartifacts
Published: 2021-05-25 10:04:45

---
title: vRA Code Stream – Preserving files and artifacts created in a CI Task
published: true
date: 2021-05-13 15:36:51 UTC
tags: General,VMware,CodeStream,preserveartifacts
canonical_url: https://veducate.co.uk/vra-code-stream-preserve-artifacts/?utm_source=rss&utm_medium=rss&utm_campaign=vra-code-stream-preserve-artifacts
---

Whilst creating a pipeline and using CI Tasks to run some CLI tools, I needed to save the outputted files from the container used for the CI Task so I could use them once the pipeline is completed.

Code Stream has a feature for CI Tasks called “[Preserve Artifacts](https://learncodestream.github.io/Pipelines/Tasks/CI/#preserve-artifacts)” to enable this, where by files in your working directory are saved to the “/sharedPath” folder location of the Docker Host where your container runs.

Below I’m going to show you how to use this feature.

- First on your pipeline configure a Working Directory

[![Code Stream - Preserve Artifacts - Pipeline - Workspace - Working Directory](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Workspace-Working-Directory.jpg?resize=604%2C310&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Workspace-Working-Directory.jpg?ssl=1)

- On your CI task steps move your outputted files to your Working Directory folder.
  - In my example I will have SSH key files created in ~/.ssh so I need to move them to my folder /workingDir which is specified at the previous steps
- Under the “Preserve Artifacts” section of the CI Task, specify the filenames you want to be preserved.

[![Code Stream - Preserve Artifacts - Pipeline - Model - CI Task - Specify the paths of the artifact to preserve](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Specify-the-paths-of-the-artifact-to-preserve.jpg?resize=604%2C544&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Specify-the-paths-of-the-artifact-to-preserve.jpg?ssl=1)

- Now run your Pipeline, open the execution and on the CI Task where your artifacts are created you will see the details of where these files are located on your Docker Host.
  - If you view the Output JSON, you can see the details you can use as outputs to reference in further tasks in the pipeline.

[![Code Stream - Preserve Artifacts - Pipeline Execution - Output - Preserve artifacts location](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Execution-Output-Preserve-artifacts-location.jpg?resize=604%2C250&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Execution-Output-Preserve-artifacts-location.jpg?ssl=1)

As an example, here I’ve setup an email notification on my pipeline task that sends me the location of the artifact on the docker host.

[![Code Stream - Preserve Artifacts - Pipeline - Model - CI Task - Create Notification](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Create-Notification.jpg?resize=511%2C311&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Create-Notification.jpg?ssl=1)

[![Code Stream - Preserve Artifacts - Pipeline - Model - CI Task - Create Notification](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Email-Notification.jpg?resize=604%2C613&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Email-Notification.jpg?ssl=1)

Here is a quick screenshot of the email from the above example.

[![Code Stream - Preserve Artifacts - Pipeline - Model - CI Task - Email Notification Example](https://i1.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Email-Notification-Example.jpg?resize=604%2C179&ssl=1)](https://i1.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Pipeline-Model-CI-Task-Email-Notification-Example.jpg?ssl=1)

- Log onto your Docker Host, and browse to the location provided on the Output

[![Code Stream - Preserve Artifacts - Docker Host - Location](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Docker-Host-Location.jpg?resize=604%2C141&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Code-Stream-Preserve-Artifacts-Docker-Host-Location.jpg?ssl=1)

Thanks to [Sam McGeown](https://twitter.com/sammcgeown) for his assistance with this!

Regards

[Follow @Saintdle](https://twitter.com/saintdle)<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

[Dean Lewis](https://uk.linkedin.com/in/saintdle?trk=profile-badge)

 

The post [vRA Code Stream – Preserving files and artifacts created in a CI Task](https://veducate.co.uk/vra-code-stream-preserve-artifacts/) appeared first on [vEducate.co.uk](https://veducate.co.uk).