await-resolve
coding-ci:awaitcoding-ci:resolve
如果你是一名 Docker 爱好者,或许有类似经历:
刚开始你建立了一条流水线,里面全部是由 Docker 组成,
突然出现一个无法用 Docker 完成的任务时,
为了照顾 no-docker,不得不重新考虑整条流水线的设计,
现在,你可以把 no-docker 的任务混编进来,其它部分保持不变。
通过这个特性,可以让多个 pipeline 相互配合,以达到跨 pipeline 、跨机器、跨集群(pipeline.runner)构建的效果
可以有多组任务,通过 key 对 await 和 resolve 进行配对。
await 会等待 resolve 的执行,resolve 的 pipeline 可以向匹配的 await pipeline 传递变量或文件。
TIP
await-resolve 同 apply、trigger 的区别:
后者指一个 pipeline 触发新事件,开启新的构建。可以跨仓库。可以异步调用,也可以同步等待。
后者指一个构建中某 pipeline 执行到 await 任务时等待对应 key 的 resolve 通知才会继续进行。
# 使用限制
- 只能对同一个事件触发的
pipeline进行关联 - 一个
resolve或await任务仅能关联一个key - 一个
key仅能关联一个resolve任务,但可以关联0或多个await任务
# 死锁检测
await 和 resolve 相互配合可以完成灵活的流程控制,但也会引入更复杂的边界情况,比如:
pipeline-1和pipeline-2相互await,即:死锁- 多条
pipeline间存在await环,即:间接死锁 await一个不存在的key,或者key没有关联resolve,即:无限等待resolve所在pipeline执行失败,对应的await陷入无限等待- 多个
resolve任务关联同一个key,即抛出异常
死锁检测 机制会自动检测以上异常,结束 await 的等待状态,抛出 dead lock found. 异常。
await 和 resolve 的在配置文件中顺序不影响运行结果,即最后 await 任务一定是会等待相应的 resolve 完成,这种情况不会被死锁检测机制终止。
# 适用事件
all
# await 参数
# resolve 参数
# key
- type:
String - required:
是
配对ID
# dist
- type:
String - required:
否
要传递的文件目录。
相对工作区,该目录下的文件都会被传递。
比如:dist: /xxx/ 可以把 /xxx/** 下的文件做为传递对象。
# data
- type:
object - required:
否
要传递的对象
key:value 格式,支持多级。示例:
- name: resolve a json
type: coding-ci:resolve
options:
key: demo
data:
a: 1
b:
c: 2
await 任务的结果,是 resolve 声明的 data 对象。
可以通过 exports 访问这个对象,示例:
- name: await a json
type: coding-ci:await
options:
key: demo
exports:
a: VAR_A
b.c: VAR_B
- name: show var
script:
- echo ${VAR_A} # 1
- echo ${VAR_B} # 2
当然,也可以不传送任务内容,仅仅表示一个等待动作:
- name: ready
type: coding-ci:resolve
options:
key: i-am-ready
- name: ready
type: coding-ci:await
options:
key: i-am-ready
# 输出结果
{
// resolve 返回的 data 内容
data
}
# 配置样例
- 传送文件
master:
push:
- runner:
tags: devnet
stages:
- name: hello
script:
- echo hello
- mkdir ./files/
- touch ./files/file1
- touch ./files/file2
- name: resolve files
type: coding-ci:resolve
options:
key: you-nide-kuaidi
dist: files
- runner:
tags: idc
stages:
- name: hello
script: echo hello
- name: await the file
type: coding-ci:await
options:
key: you-nide-kuaidi
- name: show files
script: ls -l files