func (build *execBuild) buildOnSuccessStep(logger lager.Logger, plan atc.Plan) exec.StepFactory { plan.OnSuccess.Step.Attempts = plan.Attempts step := build.buildStepFactory(logger, plan.OnSuccess.Step) plan.OnSuccess.Next.Attempts = plan.Attempts next := build.buildStepFactory(logger, plan.OnSuccess.Next) return exec.OnSuccess(step, next) }
func (build *execBuild) buildDoStep(logger lager.Logger, plan atc.Plan) exec.StepFactory { logger = logger.Session("do") var step exec.StepFactory step = exec.Identity{} for i := len(*plan.Do) - 1; i >= 0; i-- { innerPlan := (*plan.Do)[i] innerPlan.Attempts = plan.Attempts previous := build.buildStepFactory(logger, innerPlan) step = exec.OnSuccess(previous, step) } return step }
BeforeEach(func() { stepFactory = &fakes.FakeStepFactory{} successFactory = &fakes.FakeStepFactory{} step = &fakes.FakeStep{} hook = &fakes.FakeStep{} previousStep = &fakes.FakeStep{} stepFactory.UsingReturns(step) successFactory.UsingReturns(hook) repo = exec.NewSourceRepository() onSuccessFactory = exec.OnSuccess(stepFactory, successFactory) onSuccessStep = onSuccessFactory.Using(previousStep, repo) }) It("runs the success hook if the step succeeds", func() { step.ResultStub = successResult(true) process := ifrit.Background(onSuccessStep) Eventually(step.RunCallCount).Should(Equal(1)) Eventually(hook.RunCallCount).Should(Equal(1)) Eventually(process.Wait()).Should(Receive(noError())) }) It("provides the step as the previous step to the hook", func() {
func (build *execBuild) buildStepFactory(logger lager.Logger, plan atc.Plan) exec.StepFactory { if plan.Aggregate != nil { logger = logger.Session("aggregate") step := exec.Aggregate{} for _, innerPlan := range *plan.Aggregate { stepFactory := build.buildStepFactory(logger, innerPlan) step = append(step, stepFactory) } return step } if plan.Timeout != nil { step := build.buildStepFactory(logger, plan.Timeout.Step) return exec.Timeout(step, plan.Timeout.Duration) } if plan.Try != nil { step := build.buildStepFactory(logger, plan.Try.Step) return exec.Try(step) } if plan.OnSuccess != nil { step := build.buildStepFactory(logger, plan.OnSuccess.Step) next := build.buildStepFactory(logger, plan.OnSuccess.Next) return exec.OnSuccess(step, next) } if plan.OnFailure != nil { step := build.buildStepFactory(logger, plan.OnFailure.Step) next := build.buildStepFactory(logger, plan.OnFailure.Next) return exec.OnFailure(step, next) } if plan.Ensure != nil { step := build.buildStepFactory(logger, plan.Ensure.Step) next := build.buildStepFactory(logger, plan.Ensure.Next) return exec.Ensure(step, next) } if plan.Compose != nil { x := build.buildStepFactory(logger, plan.Compose.A) y := build.buildStepFactory(logger, plan.Compose.B) return exec.Compose(x, y) } if plan.Conditional != nil { logger = logger.Session("conditional", lager.Data{ "on": plan.Conditional.Conditions, }) steps := build.buildStepFactory(logger, plan.Conditional.Plan) return exec.Conditional{ Conditions: plan.Conditional.Conditions, StepFactory: steps, } } if plan.Task != nil { logger = logger.Session("task") var configSource exec.TaskConfigSource if plan.Task.Config != nil && plan.Task.ConfigPath != "" { configSource = exec.MergedConfigSource{ A: exec.FileConfigSource{plan.Task.ConfigPath}, B: exec.StaticConfigSource{*plan.Task.Config}, } } else if plan.Task.Config != nil { configSource = exec.StaticConfigSource{*plan.Task.Config} } else if plan.Task.ConfigPath != "" { configSource = exec.FileConfigSource{plan.Task.ConfigPath} } else { return exec.Identity{} } var location event.OriginLocation if plan.Location != nil { location = event.OriginLocationFrom(*plan.Location) } return build.factory.Task( exec.SourceName(plan.Task.Name), build.taskIdentifier(plan.Task.Name, location), build.delegate.ExecutionDelegate(logger, *plan.Task, location), exec.Privileged(plan.Task.Privileged), plan.Task.Tags, configSource, ) } if plan.Get != nil { logger = logger.Session("get", lager.Data{ "name": plan.Get.Name, }) var location event.OriginLocation if plan.Location != nil { location = event.OriginLocationFrom(*plan.Location) } return build.factory.Get( exec.SourceName(plan.Get.Name), build.getIdentifier(plan.Get.Name, location), build.delegate.InputDelegate(logger, *plan.Get, location), atc.ResourceConfig{ Name: plan.Get.Resource, Type: plan.Get.Type, Source: plan.Get.Source, }, plan.Get.Params, plan.Get.Tags, plan.Get.Version, ) } if plan.Put != nil { logger = logger.Session("put", lager.Data{ "name": plan.Put.Name, }) var location event.OriginLocation if plan.Location != nil { location = event.OriginLocationFrom(*plan.Location) } return build.factory.Put( build.putIdentifier(plan.Put.Name, location), build.delegate.OutputDelegate(logger, *plan.Put, location), atc.ResourceConfig{ Name: plan.Put.Resource, Type: plan.Put.Type, Source: plan.Put.Source, }, plan.Put.Tags, plan.Put.Params, ) } if plan.DependentGet != nil { logger = logger.Session("get", lager.Data{ "name": plan.DependentGet.Name, }) var location event.OriginLocation if plan.Location != nil { location = event.OriginLocationFrom(*plan.Location) } getPlan := plan.DependentGet.GetPlan() return build.factory.DependentGet( exec.SourceName(getPlan.Name), build.getIdentifier(getPlan.Name, location), build.delegate.InputDelegate(logger, getPlan, location), atc.ResourceConfig{ Name: getPlan.Resource, Type: getPlan.Type, Source: getPlan.Source, }, getPlan.Tags, getPlan.Params, ) } return exec.Identity{} }