Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:支持针对构建重放事件 #11232 #11361

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,88 @@
:icon="loading ? 'loading' : ''"
outline
theme="warning"
@click="handleClick"
@click="handleCancel"
>
{{ $t("cancel") }}
</bk-button>
<template v-else-if="!isDebugExec">
<bk-button
<bk-dropdown-menu
trigger="click"
:disabled="loading || isCurPipelineLocked"
:icon="loading ? 'loading' : ''"
outline
v-perm="{
hasPermission: canExecute,
disablePermissionApi: true,
permissionData: {
projectId,
resourceType: 'pipeline',
resourceCode: pipelineId,
action: RESOURCE_ACTION.EXECUTE
}
}"
@click="handleClick"
>
{{ $t("history.reBuild") }}
</bk-button>
<div
class="rebuild-dropdown-trigger"
slot="dropdown-trigger"
>
<i
v-if="loading"
class="devops-icon icon-circle-2-1 spin-icon"
/>
<span>{{ $t("history.reBuild") }}</span>
<i class="bk-icon icon-angle-down"></i>
</div>
<ul
class="rebuild-dropdown-content"
slot="dropdown-content"
>
<li
:class="['dropdown-item', {
'disabled': loading || isCurPipelineLocked
}]"
v-perm="{
hasPermission: canExecute,
disablePermissionApi: true,
permissionData: {
projectId,
resourceType: 'pipeline',
resourceCode: pipelineId,
action: RESOURCE_ACTION.EXECUTE
}
}"
@click="handleClick('reBuild')"
>
{{ $t("history.reBuild") }}
<bk-popover
:z-index="3000"
>
<i class="bk-icon icon-info-circle" />
<template slot="content">
<p>{{ $t('history.reBuildTips1') }}</p>
<p>{{ $t('history.reBuildTips2') }}</p>
<p>{{ $t('history.reBuildTips3') }}</p>
</template>
</bk-popover>
</li>
<li
:class="['dropdown-item', {
'disabled': loading || isCurPipelineLocked
}]"
v-perm="{
hasPermission: canExecute,
disablePermissionApi: true,
permissionData: {
projectId,
resourceType: 'pipeline',
resourceCode: pipelineId,
action: RESOURCE_ACTION.EXECUTE
}
}"
@click="handleClick('rePlay')"
>
{{ $t("history.rePlay") }}
<bk-popover
:z-index="3000"
>
<i class="bk-icon icon-info-circle" />
<template slot="content">
<p>{{ $t('history.rePlayTips1') }}</p>
<p>{{ $t('history.rePlayTips2') }}</p>
<p>{{ $t('history.rePlayTips3') }}</p>
</template>
</bk-popover>
</li>
</ul>
</bk-dropdown-menu>
<span class="exec-deatils-operate-divider"></span>
</template>
<bk-button
Expand Down Expand Up @@ -164,15 +223,11 @@
}
},
methods: {
...mapActions('pipelines', ['requestRetryPipeline', 'requestTerminatePipeline']),
async handleClick () {
...mapActions('pipelines', ['requestRetryPipeline', 'requestTerminatePipeline', 'requestRePlayPipeline']),
async handleCancel () {
try {
this.loading = true
if (this.isRunning) {
await this.stopExecute(this.execDetail?.id)
} else {
await this.retry(this.execDetail?.id)
}
await this.stopExecute(this.execDetail?.id)
} catch (err) {
this.handleError(err, {
projectId: this.$route.params.projectId,
Expand All @@ -182,15 +237,54 @@
this.loading = false
}
},
async retry (buildId, goDetail = false) {
async handleClick (type = 'reBuild') {
const h = this.$createElement
const title = type === 'reBuild' ? this.$t('history.reBuildConfirmTips') : this.$t('history.rePlayConfirmTips')
this.$bkInfo({
title,
width: 500,
confirmLoading: true,
subHeader: h('div', {
style: {
background: '#f5f6fa',
padding: '10px',
fontSize: '12px',
lineHeight: '20px'
}
}, type === 'reBuild'
? [
h('p', this.$t('history.reBuildInfo1')),
h('p', this.$t('history.reBuildInfo2'))
]
: [
h('p', this.$t('history.rePlayInfo1')),
h('p', this.$t('history.rePlayInfo2'))
]),
confirmFn: async () => {
try {
this.loading = true
await this.retry(type, this.execDetail?.id)
return true
} catch (err) {
this.handleError(err, {
projectId: this.$route.params.projectId,
resourceCode: this.$route.params.pipelineId,
action: this.$permissionResourceAction.EXECUTE
})
this.loading = false
}
}
})
},
async retry (type = 'reBuild', buildId, forceTrigger = false) {
const { projectId, pipelineId } = this.$route.params

const retryFn = type === 'reBuild' ? this.requestRetryPipeline : this.requestRePlayPipeline
// 请求执行构建
const res = await this.requestRetryPipeline({
const res = await retryFn({
...this.$route.params,
buildId
buildId,
forceTrigger
})

if (res && res.id) {
this.$router.replace({
name: 'pipelinesDetail',
Expand All @@ -208,6 +302,28 @@
message: this.$t('subpage.rebuildSuc'),
theme: 'success'
})
} else if (res.code === 2101260) {
this.loading = false
this.$bkInfo({
title: this.$t('history.rePlay'),
subTitle: res.message,
width: 500,
confirmLoading: true,
confirmFn: async () => {
try {
this.loading = true
await this.retry('rePlay', buildId, true)
return true
} catch (err) {
this.handleError(err, {
projectId: this.$route.params.projectId,
resourceCode: this.$route.params.pipelineId,
action: this.$permissionResourceAction.EXECUTE
})
this.loading = false
}
}
})
} else {
throw Error(this.$t('subpage.rebuildFail'))
}
Expand Down Expand Up @@ -277,5 +393,53 @@
padding-right: 24px;
}
}
.rebuild-dropdown-trigger {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #c4c6cc;
height: 32px;
font-size: 14px;
border-radius: 2px;
padding: 0 15px;
color: #63656E;
&:hover {
cursor: pointer;
border-color: #979ba5;
}
.icon-angle-down {
margin-left: 5px;
font-size: 16px;
}
.spin-icon {
margin-right: 5px;
color: #458bff;
z-index: 2000;
}
}
.rebuild-dropdown-content {
.dropdown-item {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
height: 32px;
line-height: 32px;
font-size: 14px;

&:hover {
background-color: #f0f1f5;
color: #3a84ff;
}
&.disabled {
cursor: not-allowed;
color: #dcdee5;
}
.icon-info-circle {
margin-left: 5px;
font-size: 12px;
}
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ const actions = {
return ajax.get(`artifactory/api/user/artifactories/${projectId}/${artifactoryType}/show?path=${path}`).then(response => {
return response.data
})
},
/**
* 重放流水线
*/
requestRePlayPipeline ({ commit, state, dispatch }, { projectId, pipelineId, buildId, forceTrigger = false }) {
return ajax.post(`${prefix}${projectId}/${pipelineId}/${buildId}/replayByBuild?forceTrigger=${forceTrigger}`).then(response => {
return response.data
}).catch(e => {
return e
})
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/frontend/locale/pipeline/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,20 @@
"copyToCustomArtifactory": "Copy to custom artifactory",
"downloading": "Downloading ",
"copySuc": " Copy {0} to custom artifactory successfully",
"buildMsg": "Build Message"
"buildMsg": "Build Message",
"rePlay": "Re-play",
"reBuildTips1": "When rebuilding, it will be re-executed with the same trigger parameters, and:",
"reBuildTips2": "- The BK_CI_BUILD_NO remains unchanged",
"reBuildTips3": "- The pipeline version used is based on the initial trigger",
"rePlayTips1": "After replaying, a new build will be initiated with the same trigger parameters:",
"rePlayTips2": "- A new BK_CI_BUILD_NO will be generated",
"rePlayTips3": "- The latest pipeline version will be used to run",
"reBuildConfirmTips": "Are you sure you want to initiate a rebuild?",
"rePlayConfirmTips": "Are you sure you want to replay the event for this pipeline?",
"rePlayInfo1": "1. When replaying, start a new Play with the same trigger parameters and the latest pipeline version.",
"rePlayInfo2": "2. When replaying, skip trigger detection, and it may not meet the trigger conditions of the latest version.",
"reBuildInfo1": "1. Rebuilding is to re-execute on the basis of the previous build.",
"reBuildInfo2": "2. Pipeline version, BK_CI_BUILD_ID are consistent with those when it is triggered for the first time."
},
"preview": {
"build": "Build",
Expand Down
15 changes: 14 additions & 1 deletion src/frontend/locale/pipeline/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,20 @@
"copyToCustomArtifactory": "复制至自定义仓库",
"downloading": "正在下载",
"copySuc": "复制{0}至自定义仓库成功",
"buildMsg": "构建信息"
"buildMsg": "构建信息",
"rePlay": "重放事件",
"reBuildTips1": "重新构建时,将以同样的触发参数重新执行,且:",
"reBuildTips2": "- BK_CI_BUILD_NO 不变",
"reBuildTips3": "- 使用的流水线版本以首次触发为准",
"rePlayTips1": "重放后,将以同样的触发参数启动一次新的构建:",
"rePlayTips2": "- 生成新的 BK_CI_BUILD_NO",
"rePlayTips3": "- 使用最新的流水线版本运行",
"reBuildConfirmTips": "确定发起重新构建吗?",
"rePlayConfirmTips": "确定针对此流水线重放事件吗?",
"rePlayInfo1": "1. 重放时,以相同的触发参数、最新的流水线编排启动一次新的构建",
"rePlayInfo2": "2. 重放时,跳过触发器检测,有可能不满足最新版本的触发条件",
"reBuildInfo1": "1. 重新构建,是在之前的构建基础上重新执行",
"reBuildInfo2": "2. 流水线编排版本、BK_CI_BUILD_ID和首次触发时一致"
},
"preview": {
"build": "构建",
Expand Down