Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit ea7ef03

Browse files
committed
Add preview docs for setup workflows
1 parent 49d7ca6 commit ea7ef03

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

docs/path-filtering.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The regular expressions support the full [Python re syntax](https://docs.python.
9191

9292
You can find more information about the elements used here:
9393

94+
- [Setup Workflows](./setup-workflows.md)
9495
- [Pipeline Variables](https://circleci.com/docs/2.0/pipeline-variables/)
9596
- [Logic Statements](https://circleci.com/docs/2.0/configuration-reference/#logic-statements)
9697
- [Conditional Steps](https://circleci.com/docs/2.0/reusing-config/#defining-conditional-steps)

docs/setup-workflows.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Setup Workflows
2+
3+
Setup workflows are a new CircleCI feature which allow users to
4+
dynamically generate configuration within a job, and by extension
5+
dynamically decide which work to execute. The resulting work will be
6+
executed within the same pipeline.
7+
8+
## Concepts
9+
10+
Setup workflows introduce new, optional pipeline lifecycle phases,
11+
which allow work to be executed. Where previously a pipeline has
12+
consisted of two phases:
13+
14+
1. Configuration Processing
15+
1. Work Execution
16+
17+
it can now have two additional phases:
18+
19+
1. *Setup* Configuration Processing
20+
1. *Setup* Work Execution
21+
1. Configuration Processing
22+
1. Work Execution
23+
24+
![Schematic](./setup-workflows.png)
25+
26+
During the first phase, the _setup configuration_ is processed, which
27+
describes the work to be executed during the _setup work execution_
28+
phase. The workflow executed as part of the _setup work execution_ phase
29+
is called a _setup workflow_. _Setup workflows_ are tagged as such in the
30+
UI and API. The _setup workflow_ then continues the pipeline to enter
31+
the next phase.
32+
33+
Behind the scenes this continuation is implemented as a call to a
34+
[public pipeline continuation API](https://circleci.com/docs/api/v2/#operation/continuePipeline). This API accepts a _continuation key_,
35+
which is a secret, unique-per-pipeline key, that is automatically
36+
injected into the environment of jobs executed as part of a setup
37+
workflow. We advise against extracting this key. It also accepts a
38+
configuration string, as well as a set of pipeline parameters.
39+
40+
We provide several orbs to cover common use cases for setup workflows,
41+
such as [path filtering](https://circleci.com/developer/orbs/orb/circleci/path-filtering).
42+
43+
This means each pipeline that has entered the setup phase has two
44+
configurations, the _setup configuration_, and the regular
45+
configuration.
46+
47+
## Limitations
48+
49+
Some limitations apply to setup workflows:
50+
51+
- the setup phase requires configuration version 2.1 or higher
52+
- a pipeline can only be continued once
53+
- a pipeline can only be continued within six hours of its creation
54+
- a pipeline cannot be continued with another setup configuration
55+
- there can only be one workflow in the setup configuration
56+
- pipeline parameters submitted at continuation time cannot overlap
57+
with pipeline parameters submitted at trigger time
58+
59+
## Enabling Setup Workflows
60+
61+
To enable setup workflows, simply enable "Setup Workflows" in the
62+
project settings (under "Advanced"). Now you can push a setup
63+
configuration to a branch. To designate a configuration as a setup
64+
configuration, and thus trigger the setup phase, use the top-level
65+
`setup: true` stanza (see below for a full example). Regardless of the
66+
project setting, only setup configurations will trigger the setup
67+
phase.
68+
69+
## Full Example
70+
71+
In this example we presume that a `generate-config` script or executable
72+
exists, which outputs a YAML string, based on some work it performs.
73+
It could potentially inspect git history, or pipeline values that get
74+
passed to it, or do anything else you can do inside a job.
75+
76+
```yaml
77+
version: 2.1
78+
79+
setup: true
80+
81+
orbs:
82+
continuation: circleci/continuation:0.1.2
83+
84+
jobs:
85+
setup:
86+
executor: continuation/default
87+
steps:
88+
- checkout
89+
- run:
90+
name: Generate config
91+
command: |
92+
./generate-config > generated_config.yml
93+
- continuation/continue:
94+
configuration_path: generated_config.yml
95+
96+
workflows:
97+
setup:
98+
jobs:
99+
- setup
100+
```
101+
102+
## Advanced Topics
103+
104+
### Using Custom Executors
105+
106+
Alternative executors can be used, but require certain dependencies to
107+
be installed for the continuation step to work (currently: `curl`,
108+
`jq`).
109+
110+
### Choosing not to Continue a Pipeline
111+
112+
If the setup workflow decides that no further work shall be executed,
113+
it is good practice to finish the pipeline, avoiding accidental
114+
continuation. The continuation orb has a command for this:
115+
116+
```yaml
117+
steps:
118+
- continuation/finish
119+
```
120+
121+
### Not Using the Continuation Orb
122+
123+
If you have special requirements not covered by the continuation orb,
124+
you can implement the same functionality in different ways. Refer to
125+
the [orb source code](https://app.circleci.com/pipelines/github/CircleCI-Public/continuation-orb) for reference.

0 commit comments

Comments
 (0)