コード例 #1
0
 @Test
 public void parameters() throws Exception {
   WorkflowJob us = j.jenkins.createProject(WorkflowJob.class, "us");
   FreeStyleProject ds = j.jenkins.createProject(FreeStyleProject.class, "ds");
   ds.addProperty(
       new ParametersDefinitionProperty(
           new StringParameterDefinition("branch", "master"),
           new BooleanParameterDefinition("extra", false, null)));
   ds.getBuildersList().add(new Shell("echo branch=$branch extra=$extra"));
   us.setDefinition(new CpsFlowDefinition("build 'ds'"));
   WorkflowRun us1 = j.assertBuildStatusSuccess(us.scheduleBuild2(0));
   FreeStyleBuild ds1 = ds.getBuildByNumber(1);
   j.assertLogContains("branch=master extra=false", ds1);
   Cause.UpstreamCause cause = ds1.getCause(Cause.UpstreamCause.class);
   assertNotNull(cause);
   assertEquals(us1, cause.getUpstreamRun());
   us.setDefinition(
       new CpsFlowDefinition(
           "build job: 'ds', parameters: [[$class: 'StringParameterValue', name: 'branch', value: 'release']]",
           true));
   j.assertBuildStatusSuccess(us.scheduleBuild2(0));
   // TODO JENKINS-13768 proposes automatic filling in of default parameter values; should that be
   // used, or is BuildTriggerStepExecution responsible, or ParameterizedJobMixIn.scheduleBuild2?
   j.assertLogContains("branch=release extra=", ds.getBuildByNumber(2));
   us.setDefinition(
       new CpsFlowDefinition(
           "build job: 'ds', parameters: [[$class: 'StringParameterValue', name: 'branch', value: 'release'], [$class: 'BooleanParameterValue', name: 'extra', value: true]]",
           true));
   j.assertBuildStatusSuccess(us.scheduleBuild2(0));
   j.assertLogContains("branch=release extra=true", ds.getBuildByNumber(3));
 }
コード例 #2
0
    @Override
    public void onDeploying(AbstractBuild<?, ?> build, String instanceId, ElasticBoxCloud cloud)
        throws IOException, InterruptedException {

      AbstractBuild<?, ?> rootBuild = build;
      for (Cause.UpstreamCause upstreamCause = build.getCause(Cause.UpstreamCause.class);
          upstreamCause != null;
          upstreamCause = rootBuild.getCause(Cause.UpstreamCause.class)) {
        Run<?, ?> run = upstreamCause.getUpstreamRun();
        if (run == null) {
          break;
        }
        rootBuild = (AbstractBuild<?, ?>) run;
      }

      TriggerCause cause = rootBuild.getCause(TriggerCause.class);
      if (cause == null) {
        return;
      }

      ConcurrentHashMap<String, PullRequestData> prDataLookup =
          getInstance().projectPullRequestDataLookup.get(rootBuild.getProject());

      if (prDataLookup != null) {
        PullRequestData data = prDataLookup.get(cause.getPullRequest().getHtmlUrl().toString());
        if (data == null) {
          data = getInstance().addPullRequestData(cause.getPullRequest(), rootBuild.getProject());
        }
        data.getInstances().add(new PullRequestInstance(instanceId, cloud.name));
        data.save();
      }
    }