Setup workflows are a new functionality we are introducing to help customers better handle their unique workflows.
What are setup workflows?
A setup workflow is a single workflow that can be used to “set up” a pipeline. It does this by using CircleCI jobs to generate or set a pipeline config and/or pipeline parameters. This enables two main use cases:
- Dynamic config: If a customer can create a script that generates a valid config at runtime, that can be used as the pipeline config
- Pre-build steps: If a customer needs to run any sort of pre-build step that does analysis to determine what to build at runtime.
One of the areas where we anticipate setup workflows being useful is in helping customers with monorepos. Different jobs can be used for solving various monorepo use cases like running git commands to analyze what files have been changed, combining multiple config files, and doing complex dependency analysis using existing build tools like Bazel. These different functions can be bundled into orbs that can be easily reused. We will be starting by releasing an orb for path filtering to set parameters based on which files have been modified in a push to filter which workflows run.
How do they work?
-
The .circleci/config.yml file will contain a single workflow with the “setup” parameter set to true. This is the setup workflow
-
(Optional) Some of the jobs within the setup workflow may generate pipeline parameters. This can be done by running user developed scripts that export these parameters as a JSON file
-
Some of the jobs within the setup workflow will generate the config. This can be done in three main ways
-
A user script within a job that programmatically generates the config from scratch
-
Pre-made config files could be placed within a file structure. If there are more than one config, a job might be required to collect/concatenate these files. If only a single file is required, then no jobs would be required.
-
A hybrid of both options.
-
At the end of the workflow, a job from the continue orb should be called. This job should take the parameters file, config file, and a continuation key generated as part of the setup workflow process as inputs and call a continuation API. This will compile the config and append it to the pipeline with the submitted parameters. (The current path filtering orb does this automatically)
-
The appended pipeline will continue running.
How do I use a setup workflow?
- Enable the Setup Workflows setting to true (it is under “Advanced” in the project settings)
- (Optional) Create a new branch for testing the setup workflow
- (Optional) Duplicate your current config to another file.
- Update your .circleci/config.yml to contain a setup workflow. This workflow will contain jobs that generate config/parameters
- (Optional) If you are setting parameters in the config, make sure any generated config has the parameters defined.
- Commit/push this branch and the setup workflows will start running
- (Optional) If you created a branch for setup workflows, you can merge it into your default branches.
More technical documentation can be found here
Orb Docs and orb source
How do I set up path filtering?
- Follow the processes for setting up a setup workflow.
- In the .circleci/config.yml, use the path filtering orb
- Use the path filter job and set up the mappings of regexes for modified files to pipeline parameters
- (Optional) Make sure the config file being set has the pipeline parameters defined, either in the file that is selected or in the scripts to generate it
- Make sure the generated config uses these pipeline parameters to filter what runs.
More technical documentation can be found here
Orb Docs and orb source
FAQs
I thought pipeline parameters could only be used with the API?
Normally this is true. But using setup workflows will allow you to set parameters when you trigger from both API or webhook (VCS push)
What is the “continuation” orb/job?
The setup workflow is used to generate parameters and config, but we need a way to signal when this work is completed and what to actually append to the pipeline. There is a Continue API that accepts the config as parameters and completes the append. The job/orb are a way of wrapping these efficiently so they are easy to use.
What is the difference between the “sandbox” and “circleci” orbs for both continuation and path filtering?
The “sandbox” versions were our experimental versions of the orbs used earlier in the preview. These orbs will no longer be receiving updates. The “circleci” orbs are where we are currently pushing all updates. If you are using code that uses the “sandbox” orbs, we recommend updating to the “circleci” orbs.