Search in sources :

Example 1 with BuildCauseOutOfDateException

use of com.thoughtworks.go.domain.buildcause.BuildCauseOutOfDateException in project gocd by gocd.

the class BuildCauseTest method shouldThrowWhenMaterialAndConfigOriginRevisionDontMatch_WhenAutoTrigger.

@Test
public void shouldThrowWhenMaterialAndConfigOriginRevisionDontMatch_WhenAutoTrigger() {
    SvnMaterial material = MaterialsMother.svnMaterial();
    MaterialConfig materialConfig = material.config();
    MaterialRevisions first = new MaterialRevisions(new MaterialRevision(material, oneModifiedFile("revision1")));
    BuildCause buildCause = BuildCause.createWithModifications(first, "");
    buildCause.setMaterialRevisions(first);
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build");
    pipelineConfig.materialConfigs().clear();
    pipelineConfig.materialConfigs().add(materialConfig);
    pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig, "plug"), "revision2"));
    try {
        buildCause.assertPipelineConfigAndMaterialRevisionMatch(pipelineConfig);
    } catch (BuildCauseOutOfDateException ex) {
        //good
        return;
    }
    fail("should have thrown");
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) BuildCauseOutOfDateException(com.thoughtworks.go.domain.buildcause.BuildCauseOutOfDateException) Test(org.junit.Test)

Example 2 with BuildCauseOutOfDateException

use of com.thoughtworks.go.domain.buildcause.BuildCauseOutOfDateException in project gocd by gocd.

the class PipelineScheduleQueue method createPipeline.

public Pipeline createPipeline(final BuildCause buildCause, final PipelineConfig pipelineConfig, final SchedulingContext context, final String md5, final Clock clock) {
    return (Pipeline) transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
            Pipeline pipeline = null;
            if (shouldCancel(buildCause, pipelineName)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(String.format("[Pipeline Schedule] Cancelling scheduling as build cause %s is the same as the most recent schedule", buildCause));
                }
                cancelSchedule(pipelineName);
            } else {
                try {
                    Pipeline newPipeline = instanceFactory.createPipelineInstance(pipelineConfig, buildCause, context, md5, clock);
                    pipeline = pipelineService.save(newPipeline);
                    finishSchedule(pipelineName, buildCause, pipeline.getBuildCause());
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(String.format("[Pipeline Schedule] Successfully scheduled pipeline %s, buildCause:%s, configOrigin: %s", pipelineName, buildCause, pipelineConfig.getOrigin()));
                    }
                } catch (BuildCauseOutOfDateException e) {
                    cancelSchedule(pipelineName);
                    LOGGER.info(String.format("[Pipeline Schedule] Build cause %s is out of date. Scheduling is cancelled. Go will reschedule this pipeline. configOrigin: %s", buildCause, pipelineConfig.getOrigin()));
                }
            }
            return pipeline;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) NullPipeline(com.thoughtworks.go.domain.NullPipeline) BuildCauseOutOfDateException(com.thoughtworks.go.domain.buildcause.BuildCauseOutOfDateException)

Aggregations

BuildCauseOutOfDateException (com.thoughtworks.go.domain.buildcause.BuildCauseOutOfDateException)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 NullPipeline (com.thoughtworks.go.domain.NullPipeline)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1