Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
f2454e84
G
gitlab-go
项目概览
徐晓伟工作室
/
gitlab-go
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-go
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f2454e84
编写于
1月 22, 2024
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🐛
根据项目路径/ID、流水线IID范围删除作业产物和作业日志(混合命令,多接口命令,立即删除):允许失败
上级
02d1e0e4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
13 deletion
+23
-13
README.md
README.md
+1
-0
mix/delete_jobs.go
mix/delete_jobs.go
+20
-12
mix/mix_delete.go
mix/mix_delete.go
+2
-1
未找到文件。
README.md
浏览文件 @
f2454e84
...
@@ -694,6 +694,7 @@ COPYRIGHT:
...
@@ -694,6 +694,7 @@ COPYRIGHT:
多个数字(使用英文逗号隔开):1,2,3,7,8,15
多个数字(使用英文逗号隔开):1,2,3,7,8,15
支持范围:5-10,
支持范围:5-10,
支持范围方向选择:-10(小于等于10,即:从 0 到 10),214-(大于等于214,即:从 214 到 214 + 10000,数据范围不超过 10000)
支持范围方向选择:-10(小于等于10,即:从 0 到 10),214-(大于等于214,即:从 214 到 214 + 10000,数据范围不超过 10000)
--allow-failure 允许失败 (default: false)
--help, -h show help
--help, -h show help
```
```
...
...
mix/delete_jobs.go
浏览文件 @
f2454e84
...
@@ -18,7 +18,8 @@ func DeleteJobs() *cli.Command {
...
@@ -18,7 +18,8 @@ func DeleteJobs() *cli.Command {
Name
:
"job"
,
Name
:
"job"
,
Aliases
:
[]
string
{
"jobs"
},
Aliases
:
[]
string
{
"jobs"
},
Usage
:
"根据项目路径/ID、流水线IID范围删除作业产物和作业日志(混合命令,多接口命令,立即删除)"
,
Usage
:
"根据项目路径/ID、流水线IID范围删除作业产物和作业日志(混合命令,多接口命令,立即删除)"
,
Flags
:
append
(
flag
.
CommonTokenRequired
(),
flag
.
Sort
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
Id
(
true
),
flag
.
IIdRange
(
true
)),
Flags
:
append
(
flag
.
CommonTokenRequired
(),
flag
.
Sort
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
Id
(
true
),
flag
.
IIdRange
(
true
),
flag
.
AllowFailure
()),
Action
:
func
(
context
*
cli
.
Context
)
error
{
Action
:
func
(
context
*
cli
.
Context
)
error
{
var
baseUrl
=
context
.
String
(
constant
.
BaseUrl
)
var
baseUrl
=
context
.
String
(
constant
.
BaseUrl
)
var
token
=
context
.
String
(
constant
.
Token
)
var
token
=
context
.
String
(
constant
.
Token
)
...
@@ -27,6 +28,7 @@ func DeleteJobs() *cli.Command {
...
@@ -27,6 +28,7 @@ func DeleteJobs() *cli.Command {
var
page
=
context
.
Int
(
constant
.
Page
)
var
page
=
context
.
Int
(
constant
.
Page
)
var
perPage
=
context
.
Int
(
constant
.
PerPage
)
var
perPage
=
context
.
Int
(
constant
.
PerPage
)
var
iidRanges
=
context
.
StringSlice
(
constant
.
IIdRange
)
var
iidRanges
=
context
.
StringSlice
(
constant
.
IIdRange
)
var
allowFailure
=
context
.
Bool
(
constant
.
AllowFailure
)
fmt
.
Println
(
iidRanges
)
fmt
.
Println
(
iidRanges
)
gitClient
,
err
:=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
baseUrl
))
gitClient
,
err
:=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
baseUrl
))
...
@@ -45,7 +47,7 @@ func DeleteJobs() *cli.Command {
...
@@ -45,7 +47,7 @@ func DeleteJobs() *cli.Command {
return
nil
return
nil
}
}
err
=
DeleteJobsRecursion
(
gitClient
,
id
,
page
,
perPage
,
sortStr
,
iids
)
err
=
DeleteJobsRecursion
(
gitClient
,
id
,
page
,
perPage
,
sortStr
,
iids
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -55,7 +57,7 @@ func DeleteJobs() *cli.Command {
...
@@ -55,7 +57,7 @@ func DeleteJobs() *cli.Command {
}
}
}
}
func
DeleteJobsRecursion
(
gitClient
*
gitlab
.
Client
,
id
interface
{},
page
int
,
perPage
int
,
sort
string
,
iids
[]
int
)
error
{
func
DeleteJobsRecursion
(
gitClient
*
gitlab
.
Client
,
id
interface
{},
page
int
,
perPage
int
,
sort
string
,
iids
[]
int
,
allowFailure
bool
)
error
{
pipelineInfos
,
response
,
err
:=
pipelines
.
ListProjectPipelines
(
gitClient
,
id
,
page
,
perPage
,
sort
)
pipelineInfos
,
response
,
err
:=
pipelines
.
ListProjectPipelines
(
gitClient
,
id
,
page
,
perPage
,
sort
)
...
@@ -78,26 +80,26 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
...
@@ -78,26 +80,26 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
if
iidsMin
==
pipelineInfo
.
IID
{
if
iidsMin
==
pipelineInfo
.
IID
{
// 等于最小值,删除最小值
// 等于最小值,删除最小值
iids
=
iids
[
1
:
]
iids
=
iids
[
1
:
]
err
=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfo
.
ID
,
1
,
100
)
err
=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfo
.
ID
,
1
,
100
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
}
else
if
pipelineInfo
.
IID
==
iidsMax
{
}
else
if
pipelineInfo
.
IID
==
iidsMax
{
// 等于最大值
// 等于最大值
iids
=
iids
[
:
len
(
iids
)
-
1
]
iids
=
iids
[
:
len
(
iids
)
-
1
]
err
=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfo
.
ID
,
1
,
100
)
err
=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfo
.
ID
,
1
,
100
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
}
else
if
iidsMin
<
pipelineInfo
.
IID
{
}
else
if
iidsMin
<
pipelineInfo
.
IID
{
// 大于最小值
// 大于最小值
err
=
jobsForExecute
(
&
iids
,
pipelineInfo
.
IID
,
gitClient
,
id
,
pipelineInfo
.
ID
)
err
=
jobsForExecute
(
&
iids
,
pipelineInfo
.
IID
,
gitClient
,
id
,
pipelineInfo
.
ID
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
}
else
if
pipelineInfo
.
IID
<
iidsMax
{
}
else
if
pipelineInfo
.
IID
<
iidsMax
{
// 小于最大值
// 小于最大值
err
=
jobsForExecute
(
&
iids
,
pipelineInfo
.
IID
,
gitClient
,
id
,
pipelineInfo
.
ID
)
err
=
jobsForExecute
(
&
iids
,
pipelineInfo
.
IID
,
gitClient
,
id
,
pipelineInfo
.
ID
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -115,7 +117,7 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
...
@@ -115,7 +117,7 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
}
}
if
len
(
pipelineInfos
)
>
0
{
if
len
(
pipelineInfos
)
>
0
{
err
:=
DeleteJobsRecursion
(
gitClient
,
id
,
page
+
1
,
perPage
,
sort
,
iids
)
err
:=
DeleteJobsRecursion
(
gitClient
,
id
,
page
+
1
,
perPage
,
sort
,
iids
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -124,13 +126,16 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
...
@@ -124,13 +126,16 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
return
nil
return
nil
}
}
func
jobsForExecute
(
iids
*
[]
int
,
pipelineInfoIId
int
,
gitClient
*
gitlab
.
Client
,
id
interface
{},
pipelineInfoId
int
)
error
{
func
jobsForExecute
(
iids
*
[]
int
,
pipelineInfoIId
int
,
gitClient
*
gitlab
.
Client
,
id
interface
{},
pipelineInfoId
int
,
allowFailure
bool
)
error
{
for
i
:=
0
;
i
<
len
(
*
iids
);
i
++
{
for
i
:=
0
;
i
<
len
(
*
iids
);
i
++
{
if
(
*
iids
)[
i
]
==
pipelineInfoIId
{
if
(
*
iids
)[
i
]
==
pipelineInfoIId
{
fmt
.
Printf
(
"数组中包含%d
\n
"
,
pipelineInfoIId
)
fmt
.
Printf
(
"数组中包含%d
\n
"
,
pipelineInfoIId
)
*
iids
=
append
((
*
iids
)[
:
i
],
(
*
iids
)[
i
+
1
:
]
...
)
*
iids
=
append
((
*
iids
)[
:
i
],
(
*
iids
)[
i
+
1
:
]
...
)
err
:=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfoId
,
1
,
100
)
err
:=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfoId
,
1
,
100
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
if
allowFailure
{
return
nil
}
return
err
return
err
}
}
break
break
...
@@ -139,7 +144,7 @@ func jobsForExecute(iids *[]int, pipelineInfoIId int, gitClient *gitlab.Client,
...
@@ -139,7 +144,7 @@ func jobsForExecute(iids *[]int, pipelineInfoIId int, gitClient *gitlab.Client,
return
nil
return
nil
}
}
func
ExecuteDeleteJobs
(
gitClient
*
gitlab
.
Client
,
id
interface
{},
pipelineInfoId
int
,
page
int
,
perPage
int
)
error
{
func
ExecuteDeleteJobs
(
gitClient
*
gitlab
.
Client
,
id
interface
{},
pipelineInfoId
int
,
page
int
,
perPage
int
,
allowFailure
bool
)
error
{
fmt
.
Printf
(
"执行删除 %d
\n
"
,
pipelineInfoId
)
fmt
.
Printf
(
"执行删除 %d
\n
"
,
pipelineInfoId
)
opt
:=
&
gitlab
.
ListJobsOptions
{
opt
:=
&
gitlab
.
ListJobsOptions
{
...
@@ -160,13 +165,16 @@ func ExecuteDeleteJobs(gitClient *gitlab.Client, id interface{}, pipelineInfoId
...
@@ -160,13 +165,16 @@ func ExecuteDeleteJobs(gitClient *gitlab.Client, id interface{}, pipelineInfoId
_
,
response
,
err
=
gitClient
.
Jobs
.
EraseJob
(
id
,
job
.
ID
)
_
,
response
,
err
=
gitClient
.
Jobs
.
EraseJob
(
id
,
job
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
if
allowFailure
{
return
nil
}
return
err
return
err
}
}
log
.
Printf
(
"Delete Project %s Job %d Response StatusCode: %d
\n
"
,
id
,
job
.
ID
,
response
.
Response
.
StatusCode
)
log
.
Printf
(
"Delete Project %s Job %d Response StatusCode: %d
\n
"
,
id
,
job
.
ID
,
response
.
Response
.
StatusCode
)
}
}
if
len
(
jobs
)
==
perPage
{
if
len
(
jobs
)
==
perPage
{
err
=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfoId
,
page
+
1
,
perPage
)
err
=
ExecuteDeleteJobs
(
gitClient
,
id
,
pipelineInfoId
,
page
+
1
,
perPage
,
allowFailure
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
mix/mix_delete.go
浏览文件 @
f2454e84
...
@@ -11,7 +11,8 @@ func Delete() *cli.Command {
...
@@ -11,7 +11,8 @@ func Delete() *cli.Command {
Name
:
"mix-delete"
,
Name
:
"mix-delete"
,
Aliases
:
[]
string
{
"mix-rm"
},
Aliases
:
[]
string
{
"mix-rm"
},
Usage
:
"删除(混合命令,多接口命令)"
,
Usage
:
"删除(混合命令,多接口命令)"
,
Flags
:
append
(
flag
.
Common
(),
flag
.
Sort
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
Id
(
false
),
flag
.
IIdRange
(
false
)),
Flags
:
append
(
flag
.
Common
(),
flag
.
Sort
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
Id
(
false
),
flag
.
IIdRange
(
false
),
flag
.
AllowFailure
()),
Subcommands
:
[]
*
cli
.
Command
{
Subcommands
:
[]
*
cli
.
Command
{
DeleteArtifacts
(),
DeleteArtifacts
(),
DeleteAllArtifacts
(),
DeleteAllArtifacts
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录