func (factory *BuildFactory) constructPlanFromConfig( planConfig atc.PlanConfig, resources atc.ResourceConfigs, inputs []db.BuildInput, hasHooks bool, ) atc.Plan { var plan atc.Plan switch { case planConfig.Do != nil: if hasHooks { plan = factory.constructPlanHookBasedPlan( *planConfig.Do, resources, inputs, ) } else { plan = factory.constructPlanSequenceBasedPlan( *planConfig.Do, resources, inputs, ) } if plan.Location == nil { plan.Location = planConfig.Location } case planConfig.Put != "": logicalName := planConfig.Put resourceName := planConfig.Resource if resourceName == "" { resourceName = logicalName } resource, _ := resources.Lookup(resourceName) putPlan := &atc.PutPlan{ Type: resource.Type, Name: logicalName, Pipeline: factory.PipelineName, Resource: resourceName, Source: resource.Source, Params: planConfig.Params, Tags: planConfig.Tags, } dependentGetPlan := &atc.DependentGetPlan{ Type: resource.Type, Name: logicalName, Pipeline: factory.PipelineName, Resource: resourceName, Params: planConfig.GetParams, Tags: planConfig.Tags, Source: resource.Source, } stepLocation := &atc.Location{} nextLocation := &atc.Location{} if planConfig.Location != nil { stepLocation.ID = planConfig.Location.ID stepLocation.Hook = planConfig.Location.Hook if planConfig.Location.ParallelGroup != 0 { stepLocation.ParallelGroup = planConfig.Location.ParallelGroup } else { stepLocation.ParentID = planConfig.Location.ParentID } nextLocation.ID = stepLocation.ID + 1 nextLocation.ParentID = stepLocation.ID } plan = atc.Plan{ // Location: planConfig.Location, OnSuccess: &atc.OnSuccessPlan{ Step: atc.Plan{ Location: stepLocation, Put: putPlan, }, Next: atc.Plan{ Location: nextLocation, DependentGet: dependentGetPlan, }, }, } case planConfig.Get != "": resourceName := planConfig.Resource if resourceName == "" { resourceName = planConfig.Get } resource, _ := resources.Lookup(resourceName) name := planConfig.Get var version db.Version for _, input := range inputs { if input.Name == name { version = input.Version break } } plan = atc.Plan{ Location: planConfig.Location, Get: &atc.GetPlan{ Type: resource.Type, Name: name, Pipeline: factory.PipelineName, Resource: resourceName, Source: resource.Source, Params: planConfig.Params, Version: atc.Version(version), Tags: planConfig.Tags, }, } case planConfig.Task != "": plan = atc.Plan{ Location: planConfig.Location, Task: &atc.TaskPlan{ Name: planConfig.Task, Privileged: planConfig.Privileged, Config: planConfig.TaskConfig, ConfigPath: planConfig.TaskConfigPath, Tags: planConfig.Tags, }, } case planConfig.Try != nil: nextStep := factory.constructPlanFromConfig( *planConfig.Try, resources, inputs, hasHooks) plan = atc.Plan{ Location: planConfig.Location, Try: &atc.TryPlan{ Step: nextStep, }, } case planConfig.Aggregate != nil: aggregate := atc.AggregatePlan{} for _, planConfig := range *planConfig.Aggregate { nextStep := factory.constructPlanFromConfig( planConfig, resources, inputs, hasHooks) aggregate = append(aggregate, nextStep) } plan = atc.Plan{ Location: planConfig.Location, Aggregate: &aggregate, } } if planConfig.Conditions != nil { plan = atc.Plan{ Conditional: &atc.ConditionalPlan{ Conditions: *planConfig.Conditions, Plan: plan, }, } } if planConfig.Timeout != "" { plan = atc.Plan{ Timeout: &atc.TimeoutPlan{ Duration: planConfig.Timeout, Step: plan, }, } } constructionParams := factory.ensureIfPresent(factory.successIfPresent(factory.failureIfPresent( constructionParams{ plan: plan, planConfig: planConfig, resources: resources, inputs: inputs, hasHooks: hasHooks, })), ) return constructionParams.plan }