cnb:await-resolve
About 562 wordsAbout 2 min
cnb:await / cnb:resolve
Wait / Notify mechanism for coordinating multiple concurrent pipelines with flexible ordering.
cnb:await: waits for the pairedcnb:resolve(identified by the samekey) to finish before continuing.cnb:resolve: notifies the waitingcnb:awaitand can pass data to it.
When configuring a step, set type to cnb:await or cnb:resolve; there is no cnb:await-resolve type.
Tips
Difference between await-resolve and apply, trigger:
The former refers to a pipeline in a build that waits at an await task until it receives a resolve notification from another pipeline corresponding to the key before continuing.
The latter triggers a new pipeline from an existing one. It can be asynchronous, synchronous, and can even span repositories.
- Usage Limitations
- Deadlock Detection
- Applicable Events
- Await Parameters
- Resolve Parameters
- Output Results
Usage Limitations
- Can only await and resolve pipelines triggered by the
same event. - A
keycan only be resolved once but can be awaited multiple times. - Group await and resolve operations using a
key. - Await-resolve tasks can only run in the 'stages' of the pipeline, not in the 'endStages' and 'failStages'.
Deadlock Detection
While await and resolve can provide flexible flow control, they can introduce complex edge cases such as:
- Deadlocks
- Pipeline-1 and Pipeline-2 await each other
- Multiple pipelines form an await loop
- Infinite waiting
- Awaiting a non-existent key or a key without a corresponding resolve
- Failure in the pipeline where resolve is executed
- Duplicate resolves
- Multiple resolve tasks associated with the same key
The deadlock detection mechanism automatically detects these anomalies, terminates the await's waiting state, and throws a dead lock found. exception.
The order of await and resolve in the configuration file does not affect the execution result. The final await task will always wait for the corresponding resolve to complete, and this scenario will not be terminated by the deadlock detection mechanism.
Applicable Events
Await Parameters
key
- type: String
- required: true
Pairing ID
Resolve Parameters
key
- type: String
- required: true
Pairing ID
data
- type: object
- required: false
Object to be passed
In key: value format, supports multiple levels. Example:
- name: resolve a json
type: cnb:resolve
options:
key: demo
data:
a: 1
b:
c: 2The result of the await task is the data object declared by resolve. This object can be accessed through exports. Example:
- name: await a json
type: cnb:await
options:
key: demo
exports:
a: VAR_A
b.c: VAR_B
- name: show var
script:
- echo ${VAR_A} # 1
- echo ${VAR_B} # 2Alternatively, you can simply indicate a waiting action without passing any content:
- name: ready
type: cnb:resolve
options:
key: i-am-ready- name: ready
type: cnb:await
options:
key: i-am-readyOutput Results
{
// Content returned by resolve
data
}