示例#1
0
func (build *execBuild) buildOnFailureStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
	plan.OnFailure.Step.Attempts = plan.Attempts
	step := build.buildStepFactory(logger, plan.OnFailure.Step)
	plan.OnFailure.Next.Attempts = plan.Attempts
	next := build.buildStepFactory(logger, plan.OnFailure.Next)
	return exec.OnFailure(step, next)
}
示例#2
0
	BeforeEach(func() {
		stepFactory = &fakes.FakeStepFactory{}
		failureFactory = &fakes.FakeStepFactory{}

		step = &fakes.FakeStep{}
		hook = &fakes.FakeStep{}

		previousStep = &fakes.FakeStep{}

		stepFactory.UsingReturns(step)
		failureFactory.UsingReturns(hook)

		repo = exec.NewSourceRepository()

		onFailureFactory = exec.OnFailure(stepFactory, failureFactory)
		onFailureStep = onFailureFactory.Using(previousStep, repo)
	})

	It("runs the failure hook if step fails", func() {
		step.ResultStub = successResult(false)

		process := ifrit.Background(onFailureStep)

		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() {
示例#3
0
文件: exec_engine.go 项目: utako/atc
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{}
}