工作流

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

产品工作流

获取工作流任务状态

注意事项

  • 目前仅支持 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 /openapi/workflows/product/task

body 参数样例

  1. {
  2. "workflow_name": "my-workflow",
  3. "project_name": "my-workflow",
  4. "input": {
  5. "target_env": "dev",
  6. "build": {
  7. "enabled": true,
  8. "service_list": [
  9. {
  10. "service_module": "svc1",
  11. "service_name": "my_service",
  12. "repo_info": [
  13. {
  14. "codehost_name": "my_codehost",
  15. "repo_namespace": "my_namespace",
  16. "repo_name": "my_repo",
  17. "branch": "main"
  18. }
  19. ],
  20. "inputs": [
  21. {
  22. "key": "mykey",
  23. "value": "myvalue"
  24. }
  25. ]
  26. }
  27. ]
  28. },
  29. "deploy": {
  30. "enabled": true,
  31. "source": "zadig",
  32. "service_list": [
  33. {
  34. "service_module": "li",
  35. "service_name": "li",
  36. "image": "xxxxx:aaaaaa"
  37. }
  38. ]
  39. }
  40. }
  41. }

body 参数说明

参数名类型描述默认值是否必须
workflow_namestring工作流名称must
project_namestring项目标识must
inputWorkflowInput执行工作流参数must
input 参数说明
参数名类型描述默认值是否必须
target_envstring目标环境名称optional
buildBuildArgs构建参数must
deployDeployArgs部署参数must
BuildArgs 参数说明
参数名类型描述默认值是否必须
enabledbool是否启用构建must
service_list[]BuildServiceInfo构建服务所需信息optional
BuildServiceInfo 参数说明
参数名类型描述默认值是否必须
service_modulestring服务组件名称must
service_namestring服务名称must
repo_info[]RepositoryInfo代码库信息optional
inputs[]UserInput构建变量optional
RepositoryInfo 参数说明
参数名类型描述默认值是否必须
codehost_namestring代码源标识must
repo_namespacestring代码库所属命名空间(组织/个人)must
repo_namestring代码库名称must
branchstring分支must
printpr ID0使用 pr 构建时必传
UserInput 参数说明
参数名类型描述默认值是否必须
keystring自定义变量的键must
valuestring自定义变量的值must
DeployArgs 参数说明
参数名类型描述默认值是否必须
enabledbool是否启用构建must
sourcestring部署镜像来源如果使用 Zadig 构建则固定为 “zadig”
service_list[]DeployServiceInfo部署服务所需信息optional
DeployServiceInfo 参数说明
参数名类型描述默认值是否必须
service_modulestring服务组件名称must
service_namestring服务名称must
imagestring镜像信息使用 Zadig 构建时不填,否则必填

正常返回

  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

Query

参数名类型描述默认值是否必须
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": "ZadigX"
  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. }

执行自定义工作流

注意事项

  1. 暂不支持通过 OpenAPI 触发自定义任务
  2. 暂不支持通过 OpenAPI 指定工作流全局变量

请求

  1. POST /openapi/workflows/custom/task

body 参数样例

  1. {
  2. "project_name": "helm",
  3. "workflow_name": "test-openapi",
  4. "inputs": [
  5. {
  6. "job_name": "build-myapps",
  7. "job_type": "zadig-build",
  8. "parameters": {
  9. "registry": "https://koderover.******.com/test",
  10. "service_list": [
  11. {
  12. "service_module": "aslan",
  13. "service_name": "zadig",
  14. "repo_info": [{
  15. "codehost_name": "koderover",
  16. "repo_namespace": "koderover",
  17. "repo_name": "zadig",
  18. "branch": "main"
  19. }]
  20. inputs: [{
  21. "key": "username",
  22. "value": "admin"
  23. },
  24. {
  25. "key": "password",
  26. "value": "ZadigX"
  27. }]
  28. }
  29. ]
  30. }
  31. },
  32. {
  33. "job_name": "deploy-myapps",
  34. "job_type": "zadig-deploy",
  35. "parameters": {
  36. "env_name": "dev",
  37. "service_list": [
  38. {
  39. "service_name": "zadig",
  40. "service_module": "aslan",
  41. "image_name": "koderover.******.com/test/aslan:main"
  42. },
  43. {
  44. "service_name": "zadig",
  45. "service_module": "zadig-portal",
  46. "image_name": "koderover.******.com/test/zadig-portal:main"
  47. }
  48. ]
  49. }
  50. {
  51. "job_name": "jira-issue-update",
  52. "job_type": "freestyle",
  53. "parameters": {
  54. "kv": [
  55. {
  56. "key": "IssueID",
  57. "value": "ZAD-10126"
  58. },
  59. {
  60. "key": "FromStatus",
  61. "value": "Testing"
  62. },
  63. {
  64. "key": "TargetStatus",
  65. "value": "ToBeReleased"
  66. }
  67. ]
  68. }
  69. },
  70. {
  71. "job_name": "deploy-my-app",
  72. "job_type": "custom-deploy",
  73. "parameters": {
  74. "target_list": [
  75. {
  76. "workload_type": "Deployment",
  77. "workload_name": "service2",
  78. "container_name": "service2",
  79. "image_name": "koderover.***.com/test/service2:0505"
  80. }
  81. ]
  82. }
  83. }
  84. ]
  85. }

body 参数说明

参数名类型描述默认值是否必须
project_namestring项目标识must
workflow_namestring自定义工作流名称must
inputs[]Input执行工作流的具体参数must

Input 参数说明

下面将分开介绍内置构建任务、部署任务、Kubernetes 部署任务、通用任务的触发参数。

构建任务

  1. {
  2. "job_name": "build-myapps", # 构建任务名称
  3. "job_type": "zadig-build", # 构建任务类型,指定为 zadig-build
  4. "parameters": {
  5. "registry": "https://koderover.******.com/test", # 镜像仓库信息
  6. "service_list": [ # 要构建的服务信息
  7. {
  8. "service_module": "aslan", # 服务组件名称
  9. "service_name": "zadig", # 服务名称
  10. "repo_info": [{ # 构建该服务组件的代码库信息
  11. "codehost_name": "koderover", # 代码源标识
  12. "repo_namespace": "koderover", # 代码库组织名/用户名
  13. "repo_name": "zadig", # 代码库名称
  14. "branch": "main" # 代码库分支
  15. }]
  16. inputs: [{ # 构建变量信息,若设置为固定值或全局变量,则无需指定
  17. "key": "username",
  18. "value": "admin"
  19. },
  20. {
  21. "key": "password",
  22. "value": "ZadigX"
  23. }]
  24. },
  25. {
  26. "service_module": "zadig-portal",
  27. "service_name": "zadig",
  28. "repo_info": [{
  29. "codehost_name": "koderover",
  30. "repo_namespace": "koderover",
  31. "repo_name": "zadig-portal",
  32. "branch": "main"
  33. }]
  34. }
  35. ]
  36. }
  37. }

部署任务

  1. {
  2. "job_name": "deploy-myapps", # 部署任务名称
  3. "job_type": "zadig-deploy", # 部署任务类型,指定为 zadig-deploy
  4. "parameters": { # 部署参数
  5. "env_name": "dev", # 待部署环境信息,若设置为固定值或全局变量,则无需配置该字段
  6. "service_list": [ # 待部署服务信息,若设置为其他任务输出,则无需配置该字段
  7. {
  8. "service_name": "zadig", # 待部署服务名称
  9. "service_module": "aslan", # 待部署服务组件名称
  10. "image_name": "koderover.***.com/test/aslan:main" # 待部署服务组件的镜像
  11. },
  12. {
  13. "service_name": "zadig",
  14. "service_module": "zadig-portal",
  15. "image_name": "koderover.***.com/test/zadig-portal:main"
  16. }
  17. ]
  18. }

Kubernetes 部署任务

  1. {
  2. "job_name": "deploy-my-app", # Kubernetes 部署任务名称
  3. "job_type": "custom-deploy", # Kubernetes 部署任务类型,指定为 custom-deploy
  4. "parameters": {
  5. "target_list": [ # 待部署容器信息,若设置为固定值,则无需指定
  6. {
  7. "workload_type": "Deployment", # 待部署容器应用的类型,支持 Deployment 以及 StatefulSet
  8. "workload_name": "service2", # 待部署容器应用的名称
  9. "container_name": "service2", # 待部署容器应用的 container 名称
  10. "image_name": "koderover.***.com/test/service2:0505" # 待部署容器的镜像信息
  11. }
  12. ]
  13. }
  14. }

通用任务

  1. {
  2. "job_name": "jira-issue-update", # 通用任务名称
  3. "job_type": "freestyle", # 通用任务类型,指定为 freestyle
  4. "parameters": { # 通用任务中的参数和值,若设置为固定值或全局变量,则无需指定
  5. "kv": [
  6. {
  7. "key": "IssueID",
  8. "value": "ZAD-10126"
  9. },
  10. {
  11. "key": "FromStatus",
  12. "value": "Testing"
  13. },
  14. {
  15. "key": "TargetStatus",
  16. "value": "ToBeReleased"
  17. }
  18. ],
  19. "repo_info": [ # 通用任务中的代码库信息
  20. {
  21. "codehost_name": "koderover", # 代码源标识
  22. "repo_namespace": "koderover", # 代码库组织名/用户名
  23. "repo_name": "zadig", # 代码库名称
  24. "branch": "task-mgr" # 代码库分支
  25. }
  26. ]
  27. }
  28. }

测试任务

  1. {
  2. "job_name": "test-myapps", # 测试任务名称
  3. "job_type": "zadig-test", # 构建任务类型,指定为 zadig-test
  4. "parameters": {
  5. "testing_list": [ # 要测试的任务信息
  6. {
  7. "testing_name": "unit-test", # 测试任务名称
  8. "repo_info": [{ # 测试任务的代码库信息
  9. "codehost_name": "koderover", # 代码源标识
  10. "repo_namespace": "koderover", # 代码库组织名/用户名
  11. "repo_name": "zadig", # 代码库名称
  12. "branch": "main" # 代码库分支
  13. }]
  14. inputs: [{ # 测试变量信息,若设置为固定值或全局变量,则无需指定
  15. "key": "username",
  16. "value": "admin"
  17. },
  18. {
  19. "key": "password",
  20. "value": "ZadigX"
  21. }]
  22. },
  23. {
  24. "testing_name": "integration-test",
  25. "repo_info": [{
  26. "codehost_name": "koderover",
  27. "repo_namespace": "koderover",
  28. "repo_name": "zadig-portal",
  29. "branch": "main"
  30. }]
  31. }
  32. ]
  33. }
  34. }

代码扫描任务

  1. {
  2. "job_name": "scan-myapps", # 代码扫描任务名称
  3. "job_type": "zadig-scanning", # 构建任务类型,指定为 zadig-scanning
  4. "parameters": {
  5. "scanning_list": [ # 代码扫描的任务信息
  6. {
  7. "scanning_name": "scan", # 代码扫描任务名称
  8. "repo_info": [{ # 代码扫描任务的代码库信息
  9. "codehost_name": "koderover", # 代码源标识
  10. "repo_namespace": "koderover", # 代码库组织名/用户名
  11. "repo_name": "zadig", # 代码库名称
  12. "branch": "main" # 代码库分支
  13. }]
  14. },
  15. {
  16. "scanning_name": "scan-1",
  17. "repo_info": [{
  18. "codehost_name": "koderover",
  19. "repo_namespace": "koderover",
  20. "repo_name": "zadig-portal",
  21. "branch": "main"
  22. }]
  23. }
  24. ]
  25. }
  26. }

正常返回

  1. {
  2. "project_name": "simple-service-demo", # 项目标识
  3. "workflow_name": "openapi-test", # 自定义工作流名称
  4. "task_id": 20 # 自定义工作流任务执行的序号 ID
  5. }

取消自定义工作流任务

请求

  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

body 参数说明

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

body 参数示例

  1. {
  2. "task_id": 2,
  3. "workflow_name": "infra-dev-workflow",
  4. "stage_name": "deploy",
  5. "approve": true,
  6. "comment": "LGTM"
  7. }

正常返回

  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. }

创建自定义工作流

请求

  1. POST /api/aslan/workflow/v4

body 参数说明

提示

该接口的参数相对复杂,自己组装比较费力。推荐先在页面中创建自定义工作流 -> 在配置页面点击 YAML -> 复制 YAML 内容后借助在线转换工具工作流 - 图1 (opens new window)来快速获得参数。

YAML Demo

参数名类型描述默认值是否必须
namestring自定义工作流标识
display_namestring自定义工作流名称
projectstring项目标识
descriptionstring自定义工作流描述信息
multi_runbool是否开启并发执行false
stages[]Stage阶段配置

Stage 参数说明

参数名描述类型必填
name阶段名称string
parallel是否开启并发执行bool
approval人工审批配置[]Approval
jobs任务配置[]interface{}

Approval 参数说明

参数名描述类型必填
enabled是否开启人工审批bool
type审批方式,可选值如下:
native(即:Zadig 审批)
lark(即:飞书审批)
stringenabled = true 时必填
native_approvalZadig 审批配置[]NativeApprovaltype = native 时必填
lark_approval飞书审批配置[]LarkApprovaltype = lark 时必填

NativeApproval 参数说明

参数名描述类型必填
approve_users审批人清单[]ApproveUser
timeout超时时间,单位分钟int
needed_approvers需要审批的人数int

ApproveUser 参数说明

参数名描述类型必填
user_name审批人的账号名称string
user_id审批人的账号 IDstring

LarkApproval 参数说明

参数名描述类型必填
approve_users审批人清单[]LarkApproveUser
timeout超时时间,单位分钟int

LarkApproveUser 参数说明

参数名描述类型必填
id审批人的账号 IDstring
name审批人的账号名称string

body 参数示例

以下 body 示例中包含 构建 -> 部署 -> 测试 -> 自定义任务四个阶段:

  1. {
  2. "name": "workflow-demo",
  3. "display_name": "workflow-demo",
  4. "project": "demo",
  5. "description": "workflow-demo description",
  6. "multi_run": true,
  7. "stages": [
  8. {
  9. "name": "构建",
  10. "parallel": true,
  11. "jobs": [
  12. {
  13. "name": "build",
  14. "type": "zadig-build",
  15. "run_policy": "",
  16. "spec": {
  17. "docker_registry_id": "62c**********",
  18. "service_and_builds": [
  19. {
  20. "service_name": "service1",
  21. "service_module": "service1",
  22. "image_name": "nginx",
  23. "value": "service1/service1",
  24. "build_name": "build-demo"
  25. }
  26. ]
  27. }
  28. }
  29. ]
  30. },
  31. {
  32. "name": "部署",
  33. "parallel": true,
  34. "approval": {
  35. "enabled": true,
  36. "type": "native",
  37. "native_approval": {
  38. "approve_users": [
  39. {
  40. "user_name": "admin",
  41. "user_id": "9792310b-**********"
  42. },
  43. {
  44. "user_name": "sre-admin",
  45. "user_id": "9837370s-**********"
  46. }
  47. ],
  48. "timeout": 5,
  49. "needed_approvers": 1
  50. }
  51. },
  52. "jobs": [
  53. {
  54. "name": "deploy",
  55. "type": "zadig-deploy",
  56. "spec": {
  57. "env": "dev",
  58. "production": false,
  59. "deploy_contents": [
  60. "image"
  61. ],
  62. "skip_check_run_status": false,
  63. "source": "fromjob",
  64. "job_name": "build",
  65. "service_and_images": [
  66. {
  67. "service_name": "service1",
  68. "service_module": "service1",
  69. "value": "service1/service1"
  70. }
  71. ]
  72. }
  73. }
  74. ]
  75. },
  76. {
  77. "name": "测试",
  78. "parallel": true,
  79. "jobs": [
  80. {
  81. "name": "test",
  82. "type": "zadig-test",
  83. "spec": {
  84. "test_type": "service_test",
  85. "source": "fromjob",
  86. "job_name": "build",
  87. "service_and_tests": [
  88. {
  89. "service_name": "service1",
  90. "service_module": "service1",
  91. "name": "smoke-test",
  92. "project_name": "voting-app"
  93. }
  94. ]
  95. }
  96. }
  97. ]
  98. },
  99. {
  100. "name": "分发",
  101. "parallel": true,
  102. "jobs": [
  103. {
  104. "name": "common",
  105. "type": "freestyle",
  106. "run_policy": "",
  107. "spec": {
  108. "properties": {
  109. "timeout": 60,
  110. "res_req": "low",
  111. "res_req_spec": {
  112. "cpu_limit": 1000,
  113. "memory_limit": 512
  114. },
  115. "cluster_id": "",
  116. "build_os": "focal",
  117. "image_id": "630xxxxxxxxxxxx",
  118. "image_from": "koderover",
  119. "envs": [
  120. {
  121. "key": "key1",
  122. "value": "val1",
  123. "type": "string",
  124. "is_credential": false
  125. }
  126. ],
  127. "cache_enable": true,
  128. "cache_dir_type": "workspace",
  129. "cache_user_dir": ""
  130. },
  131. "steps": [
  132. {
  133. "name": "tools",
  134. "type": "tools",
  135. "spec": {
  136. "installs": [
  137. {
  138. "name": "go",
  139. "version": "1.19.3",
  140. "id": "go1.19.3"
  141. }
  142. ]
  143. }
  144. },
  145. {
  146. "name": "git",
  147. "type": "git",
  148. "spec": {
  149. "repos": [
  150. {
  151. "codehost_id": 23,
  152. "repo_owner": "owner1",
  153. "repo_name": "hello",
  154. "source": "GitHub",
  155. "branch": "main",
  156. "checkout_path": "",
  157. "remote_name": "origin",
  158. "submodules": false,
  159. "hidden": false,
  160. "repo_namespace": "owner1"
  161. }
  162. ]
  163. }
  164. },
  165. {
  166. "name": "shell",
  167. "type": "shell",
  168. "spec": {
  169. "script": "#!/bin/bash\nset -e\necho hello"
  170. }
  171. }
  172. ]
  173. }
  174. }
  175. ]
  176. },
  177. {
  178. "name": "镜像分发",
  179. "parallel": true,
  180. "jobs": [
  181. {
  182. "name": "image-release",
  183. "type": "zadig-distribute-image",
  184. "run_policy": "",
  185. "isCreate": true,
  186. "spec": {
  187. "source": "fromjob",
  188. "job_name": "build",
  189. "source_registry_id": "",
  190. "target_registry_id": "630xxxxxxxxxxxx",
  191. "targets": [
  192. {
  193. "service_name": "n-1",
  194. "service_module": "nginx-latest",
  195. "image_name": "nginx",
  196. "value": "n-1/nginx-latest"
  197. }
  198. ],
  199. "timeout": 10,
  200. "cluster_id": "",
  201. "params": []
  202. }
  203. }
  204. ]
  205. }
  206. ]
  207. }

创建工作流视图

请求

  1. POST /openapi/workflows/view

body 参数说明

参数名说明类型必填
project_name项目标识string
name工作流视图名称string
workflow_list工作流列表[]Workflow

Workflow 参数说明

参数名说明类型必填
workflow_name工作流名称string
workflow_type工作流类型,可选项如下:
product(即:产品工作流)
custom(即:自定义工作流)
string

body 参数示例

  1. {
  2. "project_name": "demo",
  3. "name": "view-demo",
  4. "workflow_list": [
  5. {
  6. "workflow_name": "dev",
  7. "workflow_type": "custom"
  8. },
  9. {
  10. "workflow_name": "nacos-config-update",
  11. "workflow_type": "custom"
  12. }
  13. ]
  14. }

返回

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