工作流

本文主要介绍如何使用 Open API 来操作 Zadig 的工作流(包括工作流和自定义工作流)。

工作流

获取工作流任务状态

注意事项

  • 目前仅支持 GitLab 的 commitId 查询
  • 支持完整的 commitId 或者输入 commitId 前 8 位查询

请求

  1. GET /api/directory/workflowTask?commitId=<commitId>

Query

参数名类型描述默认值是否必须
commitIdstringcommitIdmust

正常返回

  1. [
  2. {
  3. "task_id": 49,
  4. "create_time": 1639466317,
  5. "start_time": 1639466318,
  6. "end_time": 1639466354,
  7. "status": "passed",
  8. "url": "http://my.zadig.com/v1/projects/detail/proxy/pipelines/multi/workflow-demo/49"
  9. }
  10. ]

返回说明

参数名类型描述
task_idint64任务 id
urlstring任务具体 url
statusstring任务状态
create_timeint64Unix 时间戳格式的任务创建时间
start_timeint64Unix 时间戳格式的任务开始时间
end_timeint64Unix 时间戳格式的任务结束时间

任务状态包括:created(创建中)/running(运行中)/passed(通过)/failed(失败)/timeout(超时)/cancelled(取消)

错误码对应列表

  1. {
  2. "resultCode":401,"errorMsg":"auth failed!",
  3. "resultCode":400,"errorMsg":"param is illegal!"
  4. }

工作流任务重试

注意事项

  • 需要有执行工作流的权限
  • 支持对状态是 failed(失败)/timeout(超时)/cancelled(取消) 的工作流任务进行重试

请求

  1. POST /api/directory/workflowTask/id/:id/pipelines/:pipelineName/restart

路径参数说明

参数名类型描述默认值是否必须
idint任务 id
pipelineNamestring工作流名称

正常返回

  1. {"message":"success"}

异常返回

  1. {
  2. "code": 6164,
  3. "description": "获取工作流任务失败",
  4. "extra": {},
  5. "message": "重试工作流任务失败",
  6. "type": "error"
  7. }

取消工作流任务

注意事项

  • 需要有执行工作流的权限;

请求

  1. POST /api/directory/workflowTask/id/:id/pipelines/:pipelineName/cancel

路径参数说明

参数名类型描述默认值是否必须
idint任务 id
pipelineNamestring工作流名称

正常返回

  1. {"message":"success"}

异常返回

  1. {
  2. "code": 6163,
  3. "description": "mongo: no documents in result",
  4. "extra": {},
  5. "message": "取消工作流任务失败",
  6. "type": "error"
  7. }

执行工作流

注意事项

  • 需要有执行工作流的权限;
  • 暂不支持更新环境变量;
  • 暂不支持高级选项,如工作流空间缓存和 Docker 缓存。

请求

  1. POST /api/directory/workflowTask/create

body 参数样例

  1. {
  2. "workflow_name":"autoproject-workflow-dev",
  3. "env_name":"dev",
  4. "release_images": [
  5. {
  6. "image": "ccr.ccs.tencentyun.com/trial/go-sample-site1:20211221120415-1-main",
  7. "service_name": "gss",
  8. "service_module": "go-sample-site1"
  9. },
  10. {
  11. "image": "ccr.ccs.tencentyun.com/trial/go-sample-site2:20211221120415-1-main",
  12. "service_name": "gss",
  13. "service_module": "go-sample-site2"
  14. }
  15. ],
  16. "targets":[
  17. {
  18. "name":"redis3",
  19. "service_type": "k8s",
  20. "build":{
  21. "repos":[
  22. {
  23. "repo_name":"voting-app",
  24. "branch":"master",
  25. "pr":0
  26. },
  27. {
  28. "repo_name":"zadig-infra",
  29. "branch":"master",
  30. "pr":5
  31. }
  32. ]
  33. }
  34. }
  35. ],
  36. "callback": {
  37. "callback_url": "https://callbackhost.com/callback",
  38. "callback_vars": {
  39. "k1": 1,
  40. "k2": "value2"
  41. }
  42. }
  43. }

body 参数说明

参数名类型描述默认值是否必须
workflow_namestring工作流名称must
env_namestring集成环境名称must
targets[]TargetArgs构建参数option
release_images[]Image分发镜像信息option
callbackCallback工作流执行完成回调信息option

targets 和 release_images 必须有一个参数存在

TargetArgs 参数说明
参数名类型描述默认值是否必须
namestring服务名称must
service_typestring服务部署方式,支持 k8s 或 helmk8soptional
buildBuildArgs构建参数must
BuildArgs 参数说明
参数名类型描述默认值是否必须
repos[]Repository关联代码库信息must
Repository 参数说明
参数名类型描述默认值是否必须
repo_namestring代码库名称must
branchstring分支must
printpr ID0使用 pr 构建时必传
Image 参数说明
参数名类型描述默认值是否必须
imagestring镜像信息must
service_namestring服务名称must
service_modulestring服务组件must
Callback 参数说明
参数名类型描述默认值是否必须
callback_urlstring回调地址must
callback_varsmap[string]Any回调参数optional

正常返回

  1. {
  2. "project_name": "test-project",
  3. "workflow_name": "test-project-workflow-dev",
  4. "task_id": 74
  5. }

异常返回

  1. {
  2. "code": 6540,
  3. "description": "workflow [hello-world-workflow-dev] 在项目 [hellow-world] 中已经存在!",
  4. "extra": {},
  5. "message": "新建或更新wokflow失败",
  6. "type": "error"
  7. }

获取工作流任务详情

请求

  1. GET /api/directory/workflowTask/id/:id/pipelines/:pipelineName

路径参数说明

参数名类型描述默认值是否必须
idint任务 id
pipelineNamestring工作流名称

正常返回

  1. {
  2. "workflow_name": "test-project-workflow-dev",
  3. "env_name": "dev",
  4. "targets": [
  5. {
  6. "name": "gss-1",
  7. "service_type": "helm",
  8. "build": {
  9. "repos": [
  10. {
  11. "repo_name": "hzx-test",
  12. "branch": "main",
  13. "pr": 0
  14. }
  15. ]
  16. }
  17. },
  18. {
  19. "name": "gss-2",
  20. "service_type": "helm",
  21. "build": {
  22. "repos": [
  23. {
  24. "repo_name": "hzx-test",
  25. "branch": "main",
  26. "pr": 0
  27. }
  28. ]
  29. }
  30. }
  31. ],
  32. "images": [
  33. {
  34. "image": "ccr.ccs.tencentyun.com/trial/go-sample-site:20211221120415-1-main",
  35. "service_name": "gss-1",
  36. "registry_repo" : "https://ccr.ccs.tencentyun.com/trial"
  37. },
  38. {
  39. "image": "ccr.ccs.tencentyun.com/trial/go-sample-site:20211221120415-1-main",
  40. "service_name": "gss-2",
  41. "registry_repo" : "https://ccr.ccs.tencentyun.com/trial"
  42. }
  43. ],
  44. "test_reports": [
  45. {
  46. "test_name": "test",
  47. "function_test_report": {
  48. "tests": 24,
  49. "successes": 24,
  50. "failures": 0,
  51. "skips": 0,
  52. "errors": 0,
  53. "detail_url": "/v1/projects/detail/test-project/pipelines/multi/testcase/test-project-workflow-dev/51/test/test-project-workflow-dev-51-test?is_workflow=1&service_name=test&test_type=function"
  54. }
  55. }
  56. ],
  57. "status": "timeout"
  58. }

返回说明

参数名类型描述
workflow_namestring工作流名称
env_namestring环境名称
statusstring任务状态
targets[]TargetArgs构建参数
images[]Image构建生成的镜像信息
test_reports[]TestReport测试报告信息
Image 参数说明
参数名类型描述
imagestring镜像地址
service_namestring服务名称
registry_repostring镜像仓库
TestReport 参数说明
参数名类型描述
test_namestring测试名称
function_test_reportFunctionTestReport测试报告概览
FunctionTestReport 参数说明
参数名类型描述
testsint测试用例数量
successesint成功数量
failuresint失败数量
skipsint跳过数量
errorsint错误数量
detail_urlstring测试报告详情 URL

异常返回

  1. {
  2. "code": 500,
  3. "description": "[400 BadRequest] {\"code\":6161,\"description\":\"\",\"extra\":{},\"message\":\"获取工作流任务失败\",\"type\":\"error\"}",
  4. "message": "Internal Error: "
  5. }

自定义工作流

获取自定义工作流任务详情

  1. GET /openapi/workflows/custom/task
参数名类型描述默认值是否必须
task_idint自定义工作流任务 id
workflow_namestring自定义工作流名称

正常返回

  1. {
  2. "task_id": 24, # 自定义工作流任务序号 ID
  3. "workflow_name": "build-images", # 自定义工作流名称
  4. "params": [ # 自定义工作流变量
  5. {
  6. "name": "USERNAME",
  7. "description": "",
  8. "type": "string",
  9. "value": "zadig",
  10. "default": "",
  11. "is_credential": false
  12. }
  13. ],
  14. "status": "running", # 自定义工作流任务状态
  15. "task_creator": "admin", # 自定义工作流任务触发者
  16. "create_time": 1664161285, # 工作流任务创建时间,Unix 时间戳格式
  17. "start_time": 1664161286, # 工作流任务开始执行时间,Unix 时间戳格式
  18. "end_time": 1664172997, # 工作流任务执行结束时间,Unix 时间戳格式
  19. "stages": [ # 工作流任务包含的所有阶段详情
  20. {
  21. "name": "构建", # 阶段名称
  22. "status": "passed", # 阶段状态
  23. "start_time": 1664161286, # 阶段执行开始时间,Unix 时间戳格式
  24. "end_time": 1664172974, # 阶段执行结束时间,Unix 时间戳格式
  25. "jobs": [ # 阶段中包含的所有任务详情
  26. {
  27. "name": "a-myapp-1-build-myapps",
  28. "type": "zadig-build", # 内置构建任务
  29. "status": "passed", # 任务状态
  30. "start_time": 1664172967, # 任务执行开始时间,Unix 时间戳格式
  31. "end_time": 1664172974, # 任务执行结束时间,Unix 时间戳格式
  32. "spec": { # 构建任务执行详细信息(包括代码信息、镜像信息、服务信息、服务组件信息、构建变量信息)
  33. "repos": [ # 代码信息
  34. {
  35. "source": "gitee",
  36. "repo_owner": "kr-test-dev",
  37. "repo_namespace": "kr-test-dev",
  38. "repo_name": "zadig",
  39. "remote_name": "origin",
  40. "branch": "main",
  41. "commit_id": "a13120997b95d8b63f2b5b29c700f89d38a5de54",
  42. "commit_message": "update pkg/microservice/warpdrive/config/const.go.\n\nSigned-off-by: grandy <10196377+grandy@user.noreply.gitee.com>",
  43. "address": "https://gitee.com",
  44. "author_name": "grandy"
  45. }
  46. ],
  47. "image": "koderover.tencentcloudcr.com/koderover-demo/myapp-1:20220926141606-26-main", # 镜像信息
  48. "service_name": "a", # 服务名称
  49. "service_module": "myapp-1", # 服务组件名称
  50. "envs": [ # 构建变量信息
  51. {
  52. "key": "username",
  53. "value": "admin",
  54. "type": "string",
  55. "is_credential": false
  56. },
  57. {
  58. "key": "password",
  59. "value": "zadig",
  60. "type": "string",
  61. "is_credential": true
  62. },
  63. {
  64. "key": "version",
  65. "value": "1",
  66. "type": "string",
  67. "is_credential": false
  68. }
  69. ]
  70. }
  71. }
  72. ]
  73. },
  74. {
  75. "name": "部署",
  76. "status": "passed",
  77. "start_time": 1664172974,
  78. "end_time": 1664172990,
  79. "approval": { # 审核信息
  80. "enabled": true, # 需要审核
  81. "approve_users": [ # 审核人列表
  82. {
  83. "user_name": "admin",
  84. "reject_or_approve": "approve",
  85. "comment": "LGTM",
  86. "operation_time": 1664172985
  87. }
  88. ],
  89. "timeout": 120, # 审核超时时间,单位:分钟
  90. "needed_approvers": 1, # 需要满足的审核通过人数
  91. "description": "需审核通过方可部署", # 审核描述
  92. "reject_or_approve": "approve" # approve:通过;reject:拒绝
  93. },
  94. "jobs": [
  95. {
  96. "name": "a-myapp-1-deploy-myapps",
  97. "type": "zadig-deploy", # 内置部署任务
  98. "status": "passed",
  99. "start_time": 1664172986,
  100. "end_time": 1664172990,
  101. "spec": { # 部署任务的详细信息
  102. "env": "dev",
  103. "skip_check_run_status": false, # 是否关闭服务状态检测
  104. "service_and_images": [ # 部署的服务、服务组件、镜像信息
  105. {
  106. "service_name": "a",
  107. "service_module": "myapp-1",
  108. "image": "koderover.tencentcloudcr.com/koderover-demo/myapp-1:20220926141606-26-main"
  109. }
  110. ]
  111. }
  112. }
  113. ]
  114. },
  115. {
  116. "name": "通用任务",
  117. "status": "passed",
  118. "start_time": 1664172990,
  119. "end_time": 1664172993,
  120. "jobs": [
  121. {
  122. "name": "echo-hello",
  123. "type": "freestyle", # 通用任务
  124. "status": "passed",
  125. "start_time": 1664172990,
  126. "end_time": 1664172993,
  127. "spec": { # 通用任务执行详细信息
  128. "repos": [
  129. {
  130. "source": "gitee",
  131. "repo_owner": "kr-test-dev",
  132. "repo_namespace": "kr-test-dev",
  133. "repo_name": "demo-test",
  134. "remote_name": "origin",
  135. "branch": "master",
  136. "commit_id": "2000aba9195bfce73b0a676e48c0ebfe2f59a4a9",
  137. "commit_message": "update org-debug.txt.\n\nSigned-off-by: grandy <10196377+grandy@user.noreply.gitee.com>",
  138. "address": "https://gitee.com",
  139. "author_name": "grandy"
  140. }
  141. ],
  142. "image": "",
  143. "service_name": "",
  144. "service_module": "",
  145. "envs": [
  146. {
  147. "key": "myName",
  148. "value": "zadig",
  149. "type": "string",
  150. "is_credential": false
  151. }
  152. ]
  153. }
  154. }
  155. ]
  156. },
  157. {
  158. "name": "自定义任务",
  159. "status": "passed",
  160. "start_time": 1664172993,
  161. "end_time": 1664172997,
  162. "jobs": [
  163. {
  164. "name": "say-hi",
  165. "type": "plugin", # 自定义任务
  166. "status": "passed",
  167. "start_time": 1664172993,
  168. "end_time": 1664172997,
  169. "error": "",
  170. "spec": {
  171. "name": "输出 Hello 问候信息",
  172. "is_offical": false,
  173. "description": "问候指定用户",
  174. "repo_url": "",
  175. "version": "v0.0.1",
  176. "image": "koderover.tencentcloudcr.com/koderover-public/greeting-bot:20220923-amd64",
  177. "args": [],
  178. "cmds": [],
  179. "envs": [
  180. {
  181. "name": "WHO_AM_I",
  182. "value": "Zadig"
  183. },
  184. {
  185. "name": "WEATHER_STATUS",
  186. "value": "sunny"
  187. }
  188. ],
  189. "inputs": [
  190. {
  191. "name": "who_am_i",
  192. "description": "who am i",
  193. "type": "string",
  194. "value": "Zadig",
  195. "default": "Zadig",
  196. "is_credential": false
  197. },
  198. {
  199. "name": "weather_status",
  200. "description": "what's the weather like today",
  201. "type": "choice",
  202. "value": "sunny",
  203. "choice_option": [
  204. "sunny",
  205. "cloudy",
  206. "rainy"
  207. ],
  208. "default": "sunny",
  209. "is_credential": false
  210. }
  211. ],
  212. "outputs": []
  213. }
  214. }
  215. ]
  216. }
  217. ],
  218. "project_name": "simple-service-demo", # 项目名称
  219. }

异常返回

  1. # 指定的工作流任务不存在
  2. {
  3. "code": 500,
  4. "description": "mongo: no documents in result",
  5. "message": "Internal Error: "
  6. }

执行自定义工作流

coming soon…

取消自定义工作流任务

请求

  1. DELETE /openapi/workflows/custom/task

Query

参数名类型描述默认值是否必须
task_idint自定义工作流任务 IDmust
workflow_namestring自定义工作流名称must

正常返回

  1. {
  2. "message": "success"
  3. }

异常返回

  1. # 指定的工作流任务已成功运行完毕
  2. {
  3. "code": 6163,
  4. "description": "task: build-images:20 is passed, cannot cancel",
  5. "extra": {},
  6. "message": "取消工作流任务失败",
  7. "type": "error"
  8. }
  9. # 指定的工作流或者任务不存在
  10. {
  11. "code": 6163,
  12. "description": "mongo: no documents in result",
  13. "extra": {},
  14. "message": "取消工作流任务失败",
  15. "type": "error"
  16. }

自定义工作流人工审核

请求

  1. POST /openapi/workflows/custom/task/approve

Query

参数名类型描述默认值是否必须
task_idint自定义工作流任务 IDmust
workflow_namestring自定义工作流名称must
stage_namestring自定义工作流待审核的阶段名称must
approvebool是否审核通过falseoption
commentstring审核信息option

正常返回

  1. {
  2. "message": "success"
  3. }

异常返回

  1. # 指定参数的阶段不需要审核
  2. {
  3. "code": 6169,
  4. "description": "workflow build-images ID 23 stage deploy-myapps do not need approve",
  5. "extra": {},
  6. "message": "批准工作流任务失败",
  7. "type": "error"
  8. }