This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch release-v0.19
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.19 by this push:
new ba0b393fc cherry-pick fix(bamboo): fix cicd_deployment_commits.id,
remove PlanResultKey from primary key list from BambooDeployBuild to v0.19
(#6403)
ba0b393fc is described below
commit ba0b393fc654c3077f8c6aeebd91a85eb57d0682
Author: Lynwee <[email protected]>
AuthorDate: Tue Nov 7 11:04:54 2023 +0800
cherry-pick fix(bamboo): fix cicd_deployment_commits.id, remove
PlanResultKey from primary key list from BambooDeployBuild to v0.19 (#6403)
* docs(bamboot): add some comments
* fix(bamboo): fix e2e test
* fix(bamboo): fix cicd_deployment_commits.id, remove `PlanResultKey` from
primary key list from BambooDeployBuild
---
backend/core/dal/dal.go | 2 +-
.../snapshot_tables/cicd_deployment_commits.csv | 14 ++++-----
backend/plugins/bamboo/models/deploy_build.go | 2 +-
.../plugins/bamboo/tasks/deploy_build_convertor.go | 33 ++++++++++++++++++----
4 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/backend/core/dal/dal.go b/backend/core/dal/dal.go
index 4a5b97b62..2f21b5bc3 100644
--- a/backend/core/dal/dal.go
+++ b/backend/core/dal/dal.go
@@ -127,7 +127,7 @@ type Dal interface {
Fetch(cursor Rows, dst interface{}) errors.Error
// All loads matched rows from database to `dst`, USE IT WITH CAUTIOUS!!
All(dst interface{}, clauses ...Clause) errors.Error
- // First loads first matched row from database to `dst`, error will be
returned if no records were found
+ // First loads the first matched row from database to `dst`, error will
be returned if no records were found
First(dst interface{}, clauses ...Clause) errors.Error
// Count matched rows from database
Count(clauses ...Clause) (int64, errors.Error)
diff --git
a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
index 3ab42c8d2..c4773a80e 100644
--- a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
+++ b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
@@ -1,8 +1,8 @@
id,commit_sha,cicd_scope_id,cicd_deployment_id,name,result,status,environment,created_date,started_date,finished_date,duration_sec,ref_name,repo_id,repo_url,prev_success_deployment_commit_id
-bamboo:BambooDeployBuild:1:1540097,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540097,release-1,FAILURE,DONE,dev,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540100,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540100,release-1,FAILURE,DONE,dev,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540101,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540101,release-2,FAILURE,DONE,dev,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540102,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540102,release-2,SUCCESS,DONE,dev,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540105,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540105,release-2,SUCCESS,DONE,dev,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540106,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540106,release-2,SUCCESS,DONE,dev,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540117,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540117,release-3,SUCCESS,DONE,dev,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540097:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540097:622595,release-1,FAILURE,DONE,dev,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540100:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540100:622595,release-1,FAILURE,DONE,dev,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540101:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540101:622595,release-2,FAILURE,DONE,dev,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540102:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540102:622595,release-2,SUCCESS,DONE,dev,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540105:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540105:622595,release-2,SUCCESS,DONE,dev,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540106:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540106:622595,release-2,SUCCESS,DONE,dev,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540117:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540117:622595,release-3,SUCCESS,DONE,dev,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
diff --git a/backend/plugins/bamboo/models/deploy_build.go
b/backend/plugins/bamboo/models/deploy_build.go
index 1e291ff6a..6e9299eda 100644
--- a/backend/plugins/bamboo/models/deploy_build.go
+++ b/backend/plugins/bamboo/models/deploy_build.go
@@ -26,7 +26,7 @@ import (
type BambooDeployBuild struct {
ConnectionId uint64 `json:"connection_id"
gorm:"primaryKey"`
DeployBuildId uint64 `json:"deploy_build_id"
gorm:"primaryKey"`
- PlanResultKey string `json:"planResultKey"
gorm:"primaryKey"`
+ PlanResultKey string `json:"planResultKey"`
DeploymentVersionName string `json:"deploymentVersionName"`
DeploymentState string `json:"deploymentState"`
LifeCycleState string `json:"lifeCycleState"`
diff --git a/backend/plugins/bamboo/tasks/deploy_build_convertor.go
b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
index 8e06df183..01e56b717 100644
--- a/backend/plugins/bamboo/tasks/deploy_build_convertor.go
+++ b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
@@ -19,6 +19,7 @@ package tasks
import (
"fmt"
+ "github.com/apache/incubator-devlake/core/models/common"
"reflect"
"strconv"
"time"
@@ -41,9 +42,28 @@ var ConvertDeployBuildsMeta = plugin.SubTaskMeta{
DomainTypes: []string{plugin.DOMAIN_TYPE_CICD},
}
+// deployBuildWithVcsRevision is a virtual tool layer table,
+// it's used to store records from a complicated sql
+// and generate id field for table cicd_deployment_commits.
type deployBuildWithVcsRevision struct {
- models.BambooDeployBuild
- RepositoryId int
+ ConnectionId uint64 `json:"connection_id"
gorm:"primaryKey"`
+ DeployBuildId uint64 `json:"deploy_build_id"
gorm:"primaryKey"`
+ PlanResultKey string `json:"planResultKey" `
+ DeploymentVersionName string `json:"deploymentVersionName"`
+ DeploymentState string `json:"deploymentState"`
+ LifeCycleState string `json:"lifeCycleState"`
+ StartedDate *time.Time `json:"startedDate"`
+ QueuedDate *time.Time `json:"queuedDate"`
+ ExecutedDate *time.Time `json:"executedDate"`
+ FinishedDate *time.Time `json:"finishedDate"`
+ ReasonSummary string `json:"reasonSummary"`
+ ProjectKey string `json:"project_key" gorm:"index"`
+ PlanKey string `json:"plan_key" gorm:"index"`
+ Environment string `gorm:"type:varchar(255)"`
+ PlanBranchName string `gorm:"type:varchar(255)"`
+ models.ApiBambooOperations
+ common.NoPKModel
+ RepositoryId int `json:"repository_id" gorm:"primaryKey"`
RepositoryName string
VcsRevisionKey string
ProjectPlanName string
@@ -61,6 +81,8 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext)
errors.Error {
db := taskCtx.GetDal()
logger := taskCtx.GetLogger()
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RAW_JOB_BUILD_TABLE)
+ // INNER JOIN may cause loss of deploy entities here.
+ // It is not known that bamboo deploy can be associated with commits,
so this is not an issue at the moment.
cursor, err := db.Cursor(
dal.Select("db.*, pbc.repository_id, pbc.repository_name,
pbc.vcs_revision_key, p.name as project_plan_name, p.project_name"),
dal.From("_tool_bamboo_deploy_builds AS db"),
@@ -72,9 +94,7 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext)
errors.Error {
}
defer cursor.Close()
- deployBuildIdGen :=
didgen.NewDomainIdGenerator(&models.BambooDeployBuild{})
planIdGen := didgen.NewDomainIdGenerator(&models.BambooPlan{})
-
converter, err := api.NewDataConverter(api.DataConverterArgs{
InputRowType:
reflect.TypeOf(deployBuildWithVcsRevision{}),
Input: cursor,
@@ -84,12 +104,13 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext)
errors.Error {
if input.VcsRevisionKey == "" {
return nil, nil
}
+ deploymentCommitId :=
didgen.NewDomainIdGenerator(&deployBuildWithVcsRevision{}).Generate(data.Options.ConnectionId,
input.DeployBuildId, input.RepositoryId)
deploymentCommit := &devops.CicdDeploymentCommit{
DomainEntity: domainlayer.DomainEntity{
- Id:
deployBuildIdGen.Generate(data.Options.ConnectionId, input.DeployBuildId),
+ Id: deploymentCommitId,
},
CicdScopeId:
planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),
- CicdDeploymentId:
deployBuildIdGen.Generate(data.Options.ConnectionId, input.DeployBuildId),
+ CicdDeploymentId: deploymentCommitId,
Name:
input.GenerateCICDDeploymentCommitName(),
Result: devops.GetResult(&devops.ResultRule{
Failed: []string{"Failed"},