prow/cmd/build/controller.go
func makeBuild(pj prowjobv1.ProwJob, defaultTimeout time.Duration) (*buildv1alpha1.Build, error) {
	if pj.Spec.BuildSpec == nil {
		return nil, errors.New("nil BuildSpec in spec")
	}
	buildID := pj.Status.BuildID
	if buildID == "" {
		return nil, errors.New("empty BuildID in status")
	}
	b := buildv1alpha1.Build{
		ObjectMeta: buildMeta(pj),
		Spec:       *pj.Spec.BuildSpec.DeepCopy(),
	}
	rawEnv, err := buildEnv(pj, buildID)
	if err != nil {
		return nil, fmt.Errorf("environment error: %v", err)
	}
	injectEnvironment(&b, rawEnv)
	injectedSource, err := injectSource(&b, pj)
	if err != nil {
		return nil, fmt.Errorf("inject source: %v", err)
	}
	injectTimeout(&b.Spec, pj.Spec.DecorationConfig, defaultTimeout)
	if pj.Spec.DecorationConfig != nil {
		encodedJobSpec := rawEnv[downwardapi.JobSpecEnv]
		err = decorateBuild(&b.Spec, encodedJobSpec, *pj.Spec.DecorationConfig, injectedSource)
		if err != nil {
			return nil, fmt.Errorf("decorate build: %v", err)
		}
	}

	return &b, nil
}
func makeBuild(pj prowjobv1.ProwJob, defaultTimeout time.Duration) (*buildv1alpha1.Build, error) {
	if pj.Spec.BuildSpec == nil {
		return nil, errors.New("nil BuildSpec in spec")
	}
	buildID := pj.Status.BuildID
	if buildID == "" {
		return nil, errors.New("empty BuildID in status")
	}
	b := buildv1alpha1.Build{
		ObjectMeta: buildMeta(pj),
		Spec:       *pj.Spec.BuildSpec.DeepCopy(),
	}
	rawEnv, err := buildEnv(pj, buildID)
	if err != nil {
		return nil, fmt.Errorf("environment error: %v", err)
	}
	injectEnvironment(&b, rawEnv)
	injectedSource, err := injectSource(&b, pj)
	if err != nil {
		return nil, fmt.Errorf("inject source: %v", err)
	}
	injectTimeout(&b.Spec, pj.Spec.DecorationConfig, defaultTimeout)
	if pj.Spec.DecorationConfig != nil {
		encodedJobSpec := rawEnv[downwardapi.JobSpecEnv]
		err = decorateBuild(&b.Spec, encodedJobSpec, *pj.Spec.DecorationConfig, injectedSource)
		if err != nil {
			return nil, fmt.Errorf("decorate build: %v", err)
		}
	}

	return &b, nil
}
// makeBuild creates a build from the prowjob, using the prowjob's buildspec.