Use parallel mode to fan-in and fan-out your step dependencies
In pipelines, the concept of fan-in/fan-out is depicted in the diagram below. This pipeline offers parallel sub-flows in a single pipeline. Fan-out refers to spreading a task to multiple destinations in parallel, and fan-in is the opposite, where we spread multiple different tasks to the same destination.
As you can see by the diagram, Step1 fans out to Step2 and Step4 (which run in parallel), while Step3 and Step4 fan-in to Step5.
You can achieve parallelism in your Codefresh pipelines by using the following:
- Simple parallel jobs (inserting parallel steps into a sequential pipeline)
- Full parallel mode
- Fan-out/fan-in parallel pipelines, as covered here
The Example Project
You can find the example Spring boot application on GitHub. It is a simple Hello World application that has several different types of tests we will be using to run using Codefresh’s parallel mode.
Create the Pipeline
Our pipeline will have five stages: setup, start, web-tests, smoke, and end:
You should be able to copy and paste this YAML in the in-line editor of the Codefresh UI. It will automatically clone the project for you.
Note the special use of
mode: parallel declared at the root of our yaml. This syntax makes the pipeline use the full parallel mode.
The order of your build steps doesn’t matter in this case, each step is executed according to its conditionals.
- Step1 (unit tests) fans out to Step2 and Step4 (web tests), which run in parallel
- Step3 (smoke tests) does not execute until Step2 is completed
- Step3 and Step4 fan in to the final step, Step5 (integration tests)
This pipeline consists of the following:
- A git-clone step that clones the main repository
- A build step that builds the cloned source code into a Docker image
- 5 freestyle steps that:
- Runs unit tests according to their respective @Tags
- Uses the image built in the second step as a Service container