Table of contents
Overview
Hello everyone, This article is part of the CircleCI series, The knowledge in this series is built in sequence.
Workspaces are additive-only data storage, It provides you with the ability to share data between Jobs, By persisting data to a workspace. and attach it to other jobs. Workspace is an off-container store, with additive-only permissions. View more info at CircleCI Docs
Code discovery
version: 2.1
jobs:
Build: # Job Name
docker: # in this example will built our code in docker container, however you can use linux, macOS, etc..
- image: cimg/python:3.11.3 # Spcecify The python image.
steps: # Job Steps
- checkout # checkout code from GitHub
- run: python --version # print out python version
- run:
name: "Build Python app"
command: |
cd python
python3 main.py
- run: mkdir -p workspace #1
- run: echo "Hello, workspace" > workspace/echo-output #2
- persist_to_workspace: #3
root: workspace
paths:
- echo-output
Scan_Build: # Job Name
docker: # in this example will built our code in docker container, however you can use linux, macOS, etc..
- image: cimg/python:3.11.3 # Spcecify The python image.
steps: # Job Steps
- checkout # checkout code from GitHub
- run: python --version # print out python version
- run:
name: "Scan Python app"
command: |
cd python
python3 main_scan.py
- attach_workspace: #4
at: /tmp/workspace
- run: cat /tmp/workspace/echo-output
workflows:
default:
jobs:
- Build
- Scan_Build:
requires: [Build]
#1 Create directory to store data in.
#2 print and store echo-output file in workspace directory.
#3 Type down the persist command, with passing the root directory "the created directory," Also pass the echo-output file. So, This step will store echo-output file only from workspace directory.
#4 attach workspace at another job.
As mentioned above, Workspace is an off-container store, with additive-only permissions. it'll store data just for 15 days. Surf the CircleCI Docs for more info.
That's it, Hope this article inspired you and will appreciate your feedback.
Thank you.