Skip to content

Commit

Permalink
find the origin quoted job (koderover#2418)
Browse files Browse the repository at this point in the history
* find the origin quoted job

Signed-off-by: guoyu <[email protected]>

* save origin job name

Signed-off-by: guoyu <[email protected]>

* fix origin job name

Signed-off-by: guoyu <[email protected]>

* fix

Signed-off-by: guoyu <[email protected]>

---------

Signed-off-by: guoyu <[email protected]>
Co-authored-by: guoyu <[email protected]>
  • Loading branch information
dianqihanwangzi and guoyu authored Mar 15, 2023
1 parent 17c5bc8 commit f23a604
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ type ZadigDeployJobSpec struct {
Source config.DeploySourceType `bson:"source" yaml:"source" json:"source"`
DeployContents []config.DeployContent `bson:"deploy_contents" yaml:"deploy_contents" json:"deploy_contents"`
// 当 source 为 fromjob 时需要,指定部署镜像来源是上游哪一个构建任务
JobName string `bson:"job_name" yaml:"job_name" json:"job_name"`
JobName string `bson:"job_name" yaml:"job_name" json:"job_name"`
// save the origin quoted job name
OriginJobName string `bson:"origin_job_name" yaml:"origin_job_name" json:"origin_job_name"`
ServiceAndImages []*ServiceAndImage `bson:"service_and_images" yaml:"service_and_images" json:"service_and_images"`
Services []*DeployService `bson:"services" yaml:"services" json:"services"`
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/microservice/aslan/core/workflow/service/workflow/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,21 @@ func getEnvFromCommitMsg(commitMsg string) []*commonmodels.KeyVal {
func warpJobError(jobName string, err error) error {
return fmt.Errorf("[job: %s] %v", jobName, err)
}

func getOriginJobName(workflow *commonmodels.WorkflowV4, jobName string) string {
for _, stage := range workflow.Stages {
for _, job := range stage.Jobs {
switch v := job.Spec.(type) {
case commonmodels.ZadigDistributeImageJobSpec:
if v.Source == config.SourceFromJob {
return v.JobName
}
case *commonmodels.ZadigDistributeImageJobSpec:
if v.Source == config.SourceFromJob {
return v.JobName
}
}
}
}
return jobName
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func (j *DeployJob) SetPreset() error {
if project.ProductFeature != nil {
j.spec.DeployType = project.ProductFeature.DeployType
}
// if quoted job quote another job, then use the service and image of the quoted job
if j.spec.Source == config.SourceFromJob {
j.spec.OriginJobName = j.spec.JobName
j.spec.JobName = getOriginJobName(j.workflow, j.spec.JobName)
}
return nil
}

Expand Down Expand Up @@ -175,11 +180,15 @@ func (j *DeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) {

// get deploy info from previous build job
if j.spec.Source == config.SourceFromJob {
// clear service and image list to prevent old data from remaining
// adapt to the front end, use the direct quoted job name
if j.spec.OriginJobName != "" {
j.spec.JobName = j.spec.OriginJobName
}
targets, err := j.getOriginReferedJobTargets(j.spec.JobName)
if err != nil {
return resp, fmt.Errorf("get origin refered job: %s targets failed, err: %v", j.spec.JobName, err)
}
// clear service and image list to prevent old data from remaining
j.spec.ServiceAndImages = targets
}

Expand Down

0 comments on commit f23a604

Please sign in to comment.