forked from TencentBlueKing/bk-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: 构建历史中没有流水线完成后上传的构件 TencentBlueKing#6538
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ory/src/main/kotlin/com/tencent/devops/artifactory/api/service/OpenArtifactoryResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.tencent.devops.artifactory.api.service | ||
|
||
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BK_TOKEN | ||
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID | ||
import io.swagger.annotations.Api | ||
import io.swagger.annotations.ApiOperation | ||
import io.swagger.annotations.ApiParam | ||
import javax.ws.rs.Consumes | ||
import javax.ws.rs.HeaderParam | ||
import javax.ws.rs.PUT | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.PathParam | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Api(tags = ["OPEN_ARTIFACTORY"], description = "open_artifactory") | ||
@Path("/open/artifactories/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
interface OpenArtifactoryResource { | ||
|
||
@PUT | ||
@Path("/projects/{projectId}/pipeline/{pipelineId}/buildId/{buildId}/artifactList") | ||
@ApiOperation("更新流水线构件列表") | ||
fun updateArtifactList( | ||
@ApiParam("认证token", required = true) | ||
@HeaderParam(AUTH_HEADER_DEVOPS_BK_TOKEN) | ||
token: String, | ||
@ApiParam("用户id", required = true) | ||
@HeaderParam(AUTH_HEADER_USER_ID) | ||
userId: String, | ||
@ApiParam("项目id", required = true) | ||
@PathParam("projectId") | ||
projectId: String, | ||
@ApiParam("流水线id", required = true) | ||
@PathParam("pipelineId") | ||
pipelineId: String, | ||
@ApiParam("构建id", required = true) | ||
@PathParam("buildId") | ||
buildId: String | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...y/src/main/kotlin/com/tencent/devops/artifactory/resources/OpenArtifactoryResourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.tencent.devops.artifactory.resources | ||
|
||
import com.tencent.devops.artifactory.api.service.OpenArtifactoryResource | ||
import com.tencent.devops.artifactory.service.PipelineBuildArtifactoryService | ||
import com.tencent.devops.common.api.constant.CommonMessageCode | ||
import com.tencent.devops.common.api.exception.ErrorCodeException | ||
import com.tencent.devops.common.api.util.JsonUtil | ||
import com.tencent.devops.common.client.Client | ||
import com.tencent.devops.common.client.ClientTokenService | ||
import com.tencent.devops.process.api.service.ServicePipelineRuntimeResource | ||
import org.slf4j.LoggerFactory | ||
|
||
class OpenArtifactoryResourceImpl( | ||
private val clientTokenService: ClientTokenService, | ||
private val pipelineBuildArtifactoryService: PipelineBuildArtifactoryService, | ||
private val client: Client | ||
) : OpenArtifactoryResource { | ||
|
||
override fun updateArtifactList( | ||
token: String, | ||
userId: String, | ||
projectId: String, | ||
pipelineId: String, | ||
buildId: String | ||
) { | ||
val validateTokenFlag = clientTokenService.checkToken(null, token) | ||
if (!validateTokenFlag) { | ||
throw ErrorCodeException( | ||
errorCode = CommonMessageCode.PARAMETER_IS_INVALID, | ||
params = arrayOf(token) | ||
) | ||
} | ||
|
||
val artifactList = pipelineBuildArtifactoryService.getArtifactList(userId, projectId, pipelineId, buildId) | ||
logger.info("[$pipelineId]|getArtifactList-$buildId artifact: ${JsonUtil.toJson(artifactList)}") | ||
val result = client.get(ServicePipelineRuntimeResource::class).updateArtifactList( | ||
userId = userId, | ||
projectId = projectId, | ||
pipelineId = pipelineId, | ||
buildId = buildId, | ||
artifactoryFileList = artifactList | ||
) | ||
logger.info("[$buildId]|update artifact result: ${result.status} ${result.message}") | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(OpenArtifactoryResourceImpl::class.java) | ||
} | ||
} |