Exemplo n.º 1
0
 public void addParamToPipeline(String pipeline, String paramName, String paramValue) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipeline));
   pipelineConfig.addParam(new ParamConfig(paramName, paramValue));
   writeConfigFile(cruiseConfig);
 }
Exemplo n.º 2
0
 public void addMingleConfigToPipeline(String pipelineName, MingleConfig mingleConfig) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipelineConfig =
       config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   pipelineConfig.setMingleConfig(mingleConfig);
   writeConfigFile(config);
 }
Exemplo n.º 3
0
 private void updateApproval(String pipelineName, String ftStage, Approval manualApproval) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   StageConfig config = pipelineConfig.findBy(new CaseInsensitiveString(ftStage));
   config.updateApproval(manualApproval);
   writeConfigFile(cruiseConfig);
 }
Exemplo n.º 4
0
 public PipelineConfig addStageToPipeline(String pipelineName, StageConfig stageConfig) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   pipelineConfig.add(stageConfig);
   writeConfigFile(cruiseConfig);
   return pipelineConfig;
 }
Exemplo n.º 5
0
 public void addEnvironmentVariableToPipeline(
     String pipelineName, EnvironmentVariablesConfig envVars) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   pipelineConfig.setVariables(envVars);
   writeConfigFile(cruiseConfig);
 }
Exemplo n.º 6
0
 public StageConfig removeStage(String pipelineName, String stageName) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName));
   pipelineConfig.remove(stageConfig);
   writeConfigFile(cruiseConfig);
   return stageConfig;
 }
Exemplo n.º 7
0
 public PipelineConfig removeMaterialFromPipeline(
     String pipelineName, MaterialConfig materialConfig) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipelineConfig =
       config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   pipelineConfig.removeMaterialConfig(materialConfig);
   writeConfigFile(config);
   return pipelineConfig;
 }
Exemplo n.º 8
0
 public void removeJob(String pipelineName, String stageName, String jobName) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName));
   JobConfig job = stageConfig.getJobs().getJob(new CaseInsensitiveString(jobName));
   stageConfig.getJobs().remove(job);
   writeConfigFile(cruiseConfig);
 }
Exemplo n.º 9
0
 public void addEnvironmentVariableToJob(
     String pipelineName, String stageName, String jobName, EnvironmentVariablesConfig envVars) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName));
   JobConfig jobConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString(jobName));
   jobConfig.setVariables(envVars);
   writeConfigFile(cruiseConfig);
 }
Exemplo n.º 10
0
 public PipelineConfig addMaterialToPipeline(String pipelineName, MaterialConfig materialConfig) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipelineConfig =
       config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   for (MaterialConfig materialConfig1 : new MaterialConfig[] {materialConfig}) {
     pipelineConfig.addMaterialConfig(materialConfig1);
   }
   writeConfigFile(config);
   return pipelineConfig;
 }
Exemplo n.º 11
0
  private PipelineConfig replaceMaterialConfigForPipeline(
      String pipelinename, MaterialConfigs materialConfigs) {
    CruiseConfig cruiseConfig = loadForEdit();
    PipelineConfig pipelineConfig =
        cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelinename));
    pipelineConfig.setMaterialConfigs(materialConfigs);

    writeConfigFile(cruiseConfig);
    return pipelineConfig;
  }
Exemplo n.º 12
0
 public void setRunMultipleInstance(
     String pipelineName, String stageName, String jobName, Integer runInstanceCount) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipelineConfig =
       config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   pipelineConfig
       .findBy(new CaseInsensitiveString(stageName))
       .jobConfigByInstanceName(jobName, true)
       .setRunInstanceCount(runInstanceCount);
   writeConfigFile(config);
 }
Exemplo n.º 13
0
 public void setRunOnAllAgents(
     String pipelineName, String stageName, String jobName, boolean runOnAllAgents) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipelineConfig =
       config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   pipelineConfig
       .findBy(new CaseInsensitiveString(stageName))
       .jobConfigByInstanceName(jobName, true)
       .setRunOnAllAgents(runOnAllAgents);
   writeConfigFile(config);
 }
Exemplo n.º 14
0
 public PipelineConfig addPipelineWithTemplate(
     String groupName, String pipelineName, String templateName) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       new PipelineConfig(
           new CaseInsensitiveString(pipelineName),
           MaterialConfigsMother.mockMaterialConfigs("svn:///user:pass@tmp/foo"));
   pipelineConfig.setTemplateName(new CaseInsensitiveString(templateName));
   cruiseConfig.findGroup(groupName).add(pipelineConfig);
   writeConfigFile(cruiseConfig);
   return pipelineConfig;
 }
Exemplo n.º 15
0
 public void addResourcesFor(
     String pipelineName, String stageName, String jobName, String... resources) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipelineConfig =
       config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   for (String resource : resources) {
     pipelineConfig
         .findBy(new CaseInsensitiveString(stageName))
         .jobConfigByConfigName(new CaseInsensitiveString(jobName))
         .addResource(resource);
   }
   writeConfigFile(config);
 }
Exemplo n.º 16
0
 private StageConfig pushJobIntoStage(
     String pipelineName, String stageName, JobConfig jobConfig, boolean clearExistingJobs) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
   StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName));
   if (clearExistingJobs) {
     stageConfig.allBuildPlans().clear();
   }
   stageConfig.allBuildPlans().add(jobConfig);
   writeConfigFile(cruiseConfig);
   return stageConfig;
 }
Exemplo n.º 17
0
 public PipelineConfig addPipeline(
     String pipelineName,
     String stageName,
     MaterialConfig materialConfig,
     TrackingTool trackingTool,
     String... jobs) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       goConfigMother.addPipeline(
           cruiseConfig, pipelineName, stageName, new MaterialConfigs(materialConfig), jobs);
   pipelineConfig.setTrackingTool(trackingTool);
   writeConfigFile(cruiseConfig);
   return pipelineConfig;
 }
Exemplo n.º 18
0
 public PipelineConfig addPipelineWithGroup(
     String groupName,
     String pipelineName,
     MaterialConfigs materialConfigs,
     MingleConfig mingleConfig,
     String stageName,
     String... buildNames) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       goConfigMother.addPipelineWithGroup(
           cruiseConfig, groupName, pipelineName, materialConfigs, stageName, buildNames);
   pipelineConfig.setMingleConfig(mingleConfig);
   writeConfigFile(cruiseConfig);
   return pipelineConfig;
 }
Exemplo n.º 19
0
 public PipelineConfig addPipelineWithGroup(
     String groupName,
     String pipelineName,
     MaterialConfigs materialConfigs,
     TrackingTool trackingTool,
     String stageName,
     String... jobs) {
   CruiseConfig cruiseConfig = loadForEdit();
   PipelineConfig pipelineConfig =
       goConfigMother.addPipelineWithGroup(
           cruiseConfig, groupName, pipelineName, materialConfigs, stageName, jobs);
   pipelineConfig.setTrackingTool(trackingTool);
   writeConfigFile(cruiseConfig);
   return pipelineConfig;
 }
  @Test
  public void shouldUpdateScmConfigurationOfPluggableScmMaterialsOnPipeline() {
    String jobName = "job-one";
    PipelineConfig pipelineConfig =
        setupPipelineWithScmMaterial("pipeline_with_pluggable_scm_mat", "stage", jobName);
    final Pipeline previousSuccessfulBuildWithOlderScmConfig =
        simulateSuccessfulPipelineRun(pipelineConfig);
    PipelineConfig updatedPipelineConfig =
        configHelper.updatePipeline(
            pipelineConfig.name(),
            new GoConfigFileHelper.Updater<PipelineConfig>() {
              @Override
              public void update(PipelineConfig config) {
                PluggableSCMMaterialConfig materialConfig =
                    (PluggableSCMMaterialConfig) config.materialConfigs().first();
                materialConfig
                    .getSCMConfig()
                    .getConfiguration()
                    .getProperty("password")
                    .setConfigurationValue(new ConfigurationValue("new_value"));
              }
            });

    final long jobId = rerunJob(jobName, pipelineConfig, previousSuccessfulBuildWithOlderScmConfig);

    Pipeline loadedPipeline =
        (Pipeline)
            transactionTemplate.execute(
                new TransactionCallback() {
                  public Object doInTransaction(TransactionStatus status) {
                    return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
                  }
                });

    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    Configuration updatedConfiguration =
        ((PluggableSCMMaterial)
                revisions
                    .findRevisionFor(updatedPipelineConfig.materialConfigs().first())
                    .getMaterial())
            .getScmConfig()
            .getConfiguration();
    assertThat(updatedConfiguration.size(), is(2));
    assertThat(
        updatedConfiguration.getProperty("password").getConfigurationValue(),
        is(new ConfigurationValue("new_value")));
  }
Exemplo n.º 21
0
  public PipelineConfig changeStagenameForToPipeline(
      String pipelineName, String oldStageName, String newStageName) {
    CruiseConfig config = loadForEdit();
    PipelineConfig pipelineConfig =
        config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));

    StageConfig stage = pipelineConfig.getStage(new CaseInsensitiveString(oldStageName));
    int index = pipelineConfig.indexOf(stage);

    stage =
        StageConfigMother.custom(
            newStageName,
            stage.isFetchMaterials(),
            stage.isCleanWorkingDir(),
            stage.getJobs(),
            stage.getApproval());
    pipelineConfig.set(index, stage);

    writeConfigFile(config);
    return pipelineConfig;
  }
  @Test
  public void shouldLoadPipelineAlongwithBuildCauseHavingMaterialPasswordsPopulated() {
    PipelineConfig pipelineConfig =
        PipelineConfigMother.pipelineConfig(
            "last",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    pipelineConfig.materialConfigs().clear();
    SvnMaterial onDirOne =
        MaterialsMother.svnMaterial("google.com", "dirOne", "loser", "boozer", false, "**/*.html");
    P4Material onDirTwo =
        MaterialsMother.p4Material(
            "host:987654321", "zoozer", "secret", "through-the-window", true);
    onDirTwo.setFolder("dirTwo");
    pipelineConfig.addMaterialConfig(onDirOne.config());
    pipelineConfig.addMaterialConfig(onDirTwo.config());

    configHelper.addPipeline(pipelineConfig);

    Pipeline building = PipelineMother.building(pipelineConfig);
    Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);

    final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();
    Pipeline loadedPipeline =
        (Pipeline)
            transactionTemplate.execute(
                new TransactionCallback() {
                  public Object doInTransaction(TransactionStatus status) {
                    return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
                  }
                });

    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    assertThat(
        ((SvnMaterial) revisions.findRevisionFor(onDirOne).getMaterial()).getPassword(),
        is("boozer"));
    assertThat(
        ((P4Material) revisions.findRevisionFor(onDirTwo).getMaterial()).getPassword(),
        is("secret"));
  }
  @Test // if other materials have expansion concept at some point, add more tests here
  public void shouldSetPasswordForExpandedSvnMaterial() {
    PipelineConfig pipelineConfig =
        PipelineConfigMother.pipelineConfig(
            "last",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    pipelineConfig.materialConfigs().clear();
    SvnMaterialConfig materialConfig = svnRepo.materialConfig();
    materialConfig.setConfigAttributes(
        Collections.singletonMap(SvnMaterialConfig.CHECK_EXTERNALS, String.valueOf(true)));
    materialConfig.setPassword("boozer");
    pipelineConfig.addMaterialConfig(materialConfig);
    configHelper.addPipeline(pipelineConfig);

    Pipeline loadedPipeline = createAndLoadModifyOneFilePipeline(pipelineConfig);

    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    assertThat(revisions.getRevisions().size(), is(2));
    assertThat(
        ((SvnMaterial) revisions.getRevisions().get(0).getMaterial()).getPassword(), is("boozer"));
    assertThat(
        ((SvnMaterial) revisions.getRevisions().get(1).getMaterial()).getPassword(), is("boozer"));
  }
 private long rerunJob(
     String jobName,
     PipelineConfig pipelineConfig,
     Pipeline previousSuccessfulBuildWithOlderPackageConfig) {
   Stage stage =
       instanceFactory.createStageForRerunOfJobs(
           previousSuccessfulBuildWithOlderPackageConfig.getFirstStage(),
           asList(jobName),
           new DefaultSchedulingContext(),
           pipelineConfig.getFirstStageConfig(),
           new TimeProvider(),
           configHelper.getGoConfigDao().md5OfConfigFile());
   stage = stageService.save(previousSuccessfulBuildWithOlderPackageConfig, stage);
   return stage.getFirstJob().getId();
 }
 private Pipeline createAndLoadModifyOneFilePipeline(PipelineConfig pipelineConfig) {
   MaterialConfigs expandedConfigs =
       materialExpansionService.expandMaterialConfigsForScheduling(
           pipelineConfig.materialConfigs());
   MaterialRevisions materialRevisions =
       ModificationsMother.modifyOneFile(
           MaterialsMother.createMaterialsFromMaterialConfigs(expandedConfigs));
   Pipeline building = PipelineMother.buildingWithRevisions(pipelineConfig, materialRevisions);
   Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);
   final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();
   return (Pipeline)
       transactionTemplate.execute(
           new TransactionCallback() {
             public Object doInTransaction(TransactionStatus status) {
               return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
             }
           });
 }
  @Test
  public void shouldLoadShallowCloneFlagForGitMaterialsBaseOnTheirOwnPipelineConfig()
      throws IOException {
    GitTestRepo testRepo = new GitTestRepo();

    PipelineConfig shallowPipeline =
        PipelineConfigMother.pipelineConfig(
            "shallowPipeline",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    shallowPipeline.materialConfigs().clear();
    shallowPipeline.addMaterialConfig(
        new GitMaterialConfig(testRepo.projectRepositoryUrl(), null, true));
    configHelper.addPipeline(shallowPipeline);

    PipelineConfig fullPipeline =
        PipelineConfigMother.pipelineConfig(
            "fullPipeline",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    fullPipeline.materialConfigs().clear();
    fullPipeline.addMaterialConfig(
        new GitMaterialConfig(testRepo.projectRepositoryUrl(), null, false));
    configHelper.addPipeline(fullPipeline);

    Pipeline shallowPipelineInstance = createAndLoadModifyOneFilePipeline(shallowPipeline);
    MaterialRevisions shallowRevisions =
        shallowPipelineInstance.getBuildCause().getMaterialRevisions();
    assertThat(
        ((GitMaterial) shallowRevisions.getRevisions().get(0).getMaterial()).isShallowClone(),
        is(true));

    Pipeline fullPipelineInstance = createAndLoadModifyOneFilePipeline(fullPipeline);
    MaterialRevisions fullRevisions = fullPipelineInstance.getBuildCause().getMaterialRevisions();
    assertThat(
        ((GitMaterial) fullRevisions.getRevisions().get(0).getMaterial()).isShallowClone(),
        is(false));
  }
  @Test
  public void shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound()
      throws IllegalArtifactLocationException, IOException {
    PipelineConfig pipelineConfig =
        PipelineConfigMother.pipelineConfig(
            "last",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    pipelineConfig.materialConfigs().clear();
    SvnMaterialConfig onDirOne =
        MaterialConfigsMother.svnMaterialConfig(
            "google.com", "dirOne", "loser", "boozer", false, "**/*.html");
    final P4MaterialConfig onDirTwo =
        MaterialConfigsMother.p4MaterialConfig(
            "host:987654321", "zoozer", "secret", "through-the-window", true);
    onDirTwo.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "dirTwo"));
    pipelineConfig.addMaterialConfig(onDirOne);
    pipelineConfig.addMaterialConfig(onDirTwo);

    configHelper.addPipeline(pipelineConfig);

    Pipeline building = PipelineMother.building(pipelineConfig);
    final Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);

    CruiseConfig cruiseConfig = configHelper.currentConfig();
    PipelineConfig cfg = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("last"));
    cfg.removeMaterialConfig(cfg.materialConfigs().get(1));
    configHelper.writeConfigFile(cruiseConfig);

    assertThat(
        serverHealthService.filterByScope(HealthStateScope.forPipeline("last")).size(), is(0));

    final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();

    Date currentTime = new Date(System.currentTimeMillis() - 1);
    Pipeline loadedPipeline =
        (Pipeline)
            transactionTemplate.execute(
                new TransactionCallback() {
                  public Object doInTransaction(TransactionStatus status) {
                    Pipeline loadedPipeline = null;
                    try {
                      loadedPipeline = loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
                      fail(
                          "should not have loaded pipeline with build-cause as one of the necessary materials was not found");
                    } catch (Exception e) {
                      assertThat(e, is(instanceOf(StaleMaterialsOnBuildCause.class)));
                      assertThat(
                          e.getMessage(),
                          is(
                              "Cannot load job 'last/"
                                  + pipeline.getCounter()
                                  + "/stage/1/job-one' because material "
                                  + onDirTwo
                                  + " was not found in config."));
                    }
                    return loadedPipeline;
                  }
                });

    assertThat(loadedPipeline, is(nullValue()));

    JobInstance reloadedJobInstance = jobInstanceService.buildById(jobId);
    assertThat(reloadedJobInstance.getState(), is(JobState.Completed));
    assertThat(reloadedJobInstance.getResult(), is(JobResult.Failed));

    assertThat(
        serverHealthService
            .filterByScope(HealthStateScope.forJob("last", "stage", "job-one"))
            .size(),
        is(1));
    ServerHealthState error =
        serverHealthService
            .filterByScope(HealthStateScope.forJob("last", "stage", "job-one"))
            .get(0);
    assertThat(
        error,
        is(
            ServerHealthState.error(
                "Cannot load job 'last/"
                    + pipeline.getCounter()
                    + "/stage/1/job-one' because material "
                    + onDirTwo
                    + " was not found in config.",
                "Job for pipeline 'last/"
                    + pipeline.getCounter()
                    + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed.",
                HealthStateType.general(HealthStateScope.forJob("last", "stage", "job-one")))));
    DateTime expiryTime = (DateTime) ReflectionUtil.getField(error, "expiryTime");
    assertThat(expiryTime.toDate().after(currentTime), is(true));
    assertThat(
        expiryTime.toDate().before(new Date(System.currentTimeMillis() + 5 * 60 * 1000 + 1)),
        is(true));

    String logText =
        FileUtil.readToEnd(consoleService.findConsoleArtifact(reloadedJobInstance.getIdentifier()));
    assertThat(
        logText,
        containsString(
            "Cannot load job 'last/"
                + pipeline.getCounter()
                + "/stage/1/job-one' because material "
                + onDirTwo
                + " was not found in config."));
    assertThat(
        logText,
        containsString(
            "Job for pipeline 'last/"
                + pipeline.getCounter()
                + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed."));
  }
Exemplo n.º 28
0
 public void lockPipeline(String name) {
   CruiseConfig config = loadForEdit();
   PipelineConfig pipeline = config.pipelineConfigByName(new CaseInsensitiveString(name));
   pipeline.lockExplicitly();
   writeConfigFile(config);
 }