Search in sources :

Example 1 with PathFromAncestor

use of com.thoughtworks.go.config.PathFromAncestor in project gocd by gocd.

the class FetchTaskBuilder method resolveTargetJob.

private JobIdentifier resolveTargetJob(FetchTask task, Pipeline currentPipeline, UpstreamPipelineResolver resolver) {
    PathFromAncestor pipelineNamePathFromAncestor = task.getPipelineNamePathFromAncestor();
    if (pipelineNamePathFromAncestor == null || CaseInsensitiveString.isBlank(pipelineNamePathFromAncestor.getPath()) || CaseInsensitiveString.areEqual(new CaseInsensitiveString(currentPipeline.getName()), pipelineNamePathFromAncestor.getPath())) {
        task.setPipelineName(new CaseInsensitiveString(currentPipeline.getName()));
        String stageCounter = JobIdentifier.LATEST;
        if (currentPipeline.hasStageBeenRun(CaseInsensitiveString.str(task.getStage()))) {
            stageCounter = String.valueOf(currentPipeline.findStage(CaseInsensitiveString.str(task.getStage())).getCounter());
        }
        return new JobIdentifier(new StageIdentifier(currentPipeline.getName(), currentPipeline.getCounter(), currentPipeline.getLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
    } else {
        DependencyMaterialRevision revision = null;
        if (pipelineNamePathFromAncestor.isAncestor()) {
            BuildCause buildCause = currentPipeline.getBuildCause();
            for (CaseInsensitiveString parentPipelineName : pipelineNamePathFromAncestor.pathToAncestor()) {
                DependencyMaterialRevision dependencyMaterialRevision = dmrForPipeline(parentPipelineName, buildCause);
                if (dependencyMaterialRevision == null) {
                    throw bomb(String.format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, parentPipelineName));
                }
                buildCause = resolver.buildCauseFor(dependencyMaterialRevision.getPipelineName(), dependencyMaterialRevision.getPipelineCounter());
            }
            revision = dmrForPipeline(pipelineNamePathFromAncestor.getAncestorName(), buildCause);
            if (revision == null) {
                throw bomb(String.format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, pipelineNamePathFromAncestor.getAncestorName()));
            }
        } else {
            revision = dmrForPipeline(pipelineNamePathFromAncestor.getPath(), currentPipeline.getBuildCause());
            if (revision == null) {
                throw bomb(String.format("Pipeline [%s] tries to fetch artifact from job [%s/%s/%s] " + "which is not a dependency material", currentPipeline.getName(), pipelineNamePathFromAncestor, task.getStage(), task.getJob()));
            }
        }
        String stageCounter = JobIdentifier.LATEST;
        if (task.getStage().equals(new CaseInsensitiveString(revision.getStageName()))) {
            stageCounter = String.valueOf(revision.getStageCounter());
        }
        return new JobIdentifier(new StageIdentifier(CaseInsensitiveString.str(pipelineNamePathFromAncestor.getAncestorName()), revision.getPipelineCounter(), revision.getPipelineLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
    }
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) PathFromAncestor(com.thoughtworks.go.config.PathFromAncestor) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Aggregations

CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 PathFromAncestor (com.thoughtworks.go.config.PathFromAncestor)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)1 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)1