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 within the same pipeline. Fan-out refers to spreading a task to multiple destinations in parallel, and fan-in is the opposite, where we spread multiple tasks to the same destination.
As you can see in 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 described in this article
You can find the example Spring boot application on GitHub. It is a simple Hello World application with several different types of tests we will use 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 in the Codefresh UI. It will automatically clone the project for you.
Note the special use of
mode: paralleldeclared 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 condition.
- 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 does the following:
- Clones the main repository through a Git-clone step.
- Builds the cloned source code into a Docker image through a build step.
- Runs freestyle steps that:
- Run unit tests according to their respective @Tags
- Use the image built in the second step as a service container