forked from Gitlink/forgeplus
流水线步骤新增、更新
This commit is contained in:
parent
da1a992670
commit
4ac7634031
|
@ -4383,72 +4383,16 @@ http://localhost:3000/api/ci/pipelines/1/2/steps.json | jq
|
|||
|
||||
------
|
||||
|
||||
#### 流水线阶段步骤新增
|
||||
#### 流水线阶段步骤新增/更新
|
||||
|
||||
```
|
||||
POST /api/ci/pipelines/{id}/{stage_id}/create_step
|
||||
PUT /api/ci/pipelines/{id}/{stage_id}/stage_step
|
||||
```
|
||||
|
||||
*示例*
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'http://localhost:3000/api/ci/pipelines/14/20/create_step.json' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw ' {"steps":[{
|
||||
"step_name": "编译构建-gradle",
|
||||
"show_index": 1,
|
||||
"content": "xxxxxxxxxxx",
|
||||
"template_id":1
|
||||
},
|
||||
{
|
||||
"step_name": "编译构建-maven",
|
||||
"show_index": 1,
|
||||
"content": "xxxxxxxxxxx",
|
||||
"template_id":1
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
*请求参数说明:*
|
||||
|
||||
| 参数名 | 必选 | 类型 | 说明 |
|
||||
| ----------- | ---- | ------ | ------------------------- |
|
||||
| steps | 是 | arr | 需要新增的步骤数组 |
|
||||
| id | 是 | int | 流水线id |
|
||||
| stage_id | 是 | int | 阶段id |
|
||||
| step_name | 是 | string | 阶段名称(阶段名-模板名) |
|
||||
| content | 是 | string | 步骤内容 |
|
||||
| template_id | 是 | int | 模板id |
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------- | ------ | ------------ |
|
||||
| status | int | 状态码 0成功 |
|
||||
| message | string | 返回消息 |
|
||||
|
||||
返回值
|
||||
|
||||
```json
|
||||
{
|
||||
"status": 0,
|
||||
"message": "success"
|
||||
}
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
#### 流水线阶段步骤更新
|
||||
|
||||
```
|
||||
PUT /api/ci/pipelines/{id}/{stage_id}/update_step
|
||||
```
|
||||
|
||||
*示例*
|
||||
|
||||
```bash
|
||||
curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/update_step.json' \
|
||||
curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/stage_step.json' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw ' {"steps":[{
|
||||
"id":7,
|
||||
|
@ -4470,14 +4414,14 @@ curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/update
|
|||
|
||||
*请求参数说明:*
|
||||
|
||||
| 参数名 | 必选 | 类型 | 说明 |
|
||||
| ----------- | ---- | ------ | ------------------------- |
|
||||
| steps | 是 | arr | 需要更新step数组 |
|
||||
| id | 是 | int | 流水线id |
|
||||
| stage_id | 是 | int | 阶段id |
|
||||
| step_name | 是 | string | 阶段名称(阶段名-模板名) |
|
||||
| content | 是 | string | 步骤内容 |
|
||||
| template_id | 是 | int | 模板id |
|
||||
| 参数名 | 必选 | 类型 | 说明 |
|
||||
| ----------- | ---- | ------ | -------------------------------- |
|
||||
| steps | 是 | arr | 需要更新step数组 |
|
||||
| id | 是 | int | 流水线id |
|
||||
| step_id | 是 | int | 阶段id(存在则更新,不存在新增) |
|
||||
| step_name | 是 | string | 阶段名称(阶段名-模板名) |
|
||||
| content | 是 | string | 步骤内容 |
|
||||
| template_id | 是 | int | 模板id |
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
|
|
|
@ -123,6 +123,28 @@ class Ci::PipelinesController < ApplicationController
|
|||
@pipeline_stage_steps = Ci::PipelineStageStep.where('stage_id=?', params[:stage_id]).order('show_index asc')
|
||||
end
|
||||
|
||||
def stage_step
|
||||
ActiveRecord::Base.transaction do
|
||||
steps = params[:steps]
|
||||
unless steps.empty?
|
||||
steps.each do |step|
|
||||
if !step[:id]
|
||||
step = Ci::PipelineStageStep.new(step_name: step[:step_name], stage_id: params[:stage_id],
|
||||
template_id: step[:template_id], content: step[:content], show_index: step[:show_index])
|
||||
step.save!
|
||||
else
|
||||
pipeline_stage_step = Ci::PipelineStageStep.find(step[:id])
|
||||
pipeline_stage_step.update(step_name: step[:step_name], content: step[:content],
|
||||
show_index: step[:show_index], template_id: step[:template_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
def create_stage_step
|
||||
ActiveRecord::Base.transaction do
|
||||
steps = params[:steps]
|
||||
|
|
|
@ -50,6 +50,7 @@ Rails.application.routes.draw do
|
|||
put :update_stage, :path => ":stage_id/update_stage", to: 'pipelines#update_stage'
|
||||
get :stage_steps, :path => ":stage_id/steps", to: 'pipelines#steps'
|
||||
post :create_stage_step, :path => ":stage_id/create_step", to: 'pipelines#create_stage_step'
|
||||
post :stage_step, :path => ":stage_id/stage_step", to: 'pipelines#stage_step'
|
||||
delete :delete_stage_step, :path => ":stage_id/:step_id/delete_step", to: 'pipelines#delete_stage_step'
|
||||
put :update_stage_step, :path => ":stage_id/update_step", to: 'pipelines#update_stage_step'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue