コード例 #1
0
  @Override
  public void run() {
    ReviewInput reviewInput = createReview();

    String reviewEndpoint = resolveEndpointURL();

    HttpPost httpPost = createHttpPostEntity(reviewInput, reviewEndpoint);

    if (httpPost == null) {
      return;
    }

    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient
        .getCredentialsProvider()
        .setCredentials(
            new AuthScope(null, -1),
            new UsernamePasswordCredentials(
                config.getGerritHttpUserName(), config.getGerritHttpPassword()));
    try {
      HttpResponse httpResponse = httpclient.execute(httpPost);
      String response = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8");
      listener.getLogger().print(response);
      if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        listener.error(httpResponse.getStatusLine().getReasonPhrase());
      }
    } catch (Exception e) {
      listener.error("Failed to submit result", e);
    }
  }
コード例 #2
0
 public String generateSlaveXml(String id, String java, String args) throws IOException {
   String xml =
       IOUtils.toString(this.getClass().getResourceAsStream("jenkins-slave.xml"), "UTF-8");
   xml = xml.replace("@ID@", id);
   xml = xml.replace("@JAVA@", java);
   xml = xml.replace("@ARGS@", args);
   return xml;
 }
コード例 #3
0
 private int readSmbFile(SmbFile f) throws IOException {
   InputStream in = null;
   try {
     in = f.getInputStream();
     return Integer.parseInt(IOUtils.toString(in));
   } finally {
     IOUtils.closeQuietly(in);
   }
 }
コード例 #4
0
ファイル: WebHook.java プロジェクト: ndeloof/xpdev-plugin
  public void doIndex(StaplerRequest req) throws IOException {
    String payload = IOUtils.toString(req.getReader());
    LOGGER.fine("Full details of the POST was " + payload);

    JSONObject o = JSONObject.fromObject(payload);
    String repoUrl = o.getString("repository_ssl_path");
    LOGGER.info("Received POST for " + repoUrl);

    // run in high privilege to see all the projects anonymous users don't see.
    // this is safe because when we actually schedule a build, it's a build that can
    // happen at some random time anyway.

    // TODO replace with ACL.impersonate as LTS is > 1.461
    Authentication old = SecurityContextHolder.getContext().getAuthentication();
    SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
    try {
      for (AbstractProject<?, ?> job : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
        boolean found = false;
        SCM scm = job.getScm();
        if (scm instanceof SubversionSCM) {
          found = hasRepository(repoUrl, (SubversionSCM) scm);
        } else if (scm instanceof GitSCM) {
          found = hasRepository(repoUrl, (GitSCM) scm);
        } else if (scm instanceof MercurialSCM) {
          found = hasRepository(repoUrl, (MercurialSCM) scm);
        }

        if (found) {
          LOGGER.info(job.getFullDisplayName() + " triggered by web hook.");
          job.scheduleBuild(new WebHookCause());
        }

        LOGGER.fine(
            "Skipped "
                + job.getFullDisplayName()
                + " because it doesn't have a matching repository.");
      }
    } finally {
      SecurityContextHolder.getContext().setAuthentication(old);
    }
  }
コード例 #5
0
  /**
   * Also applicable for workflow jobs.
   *
   * @throws Exception
   */
  @Issue("JENKINS-30357")
  @Test
  public void testWorkflow() throws Exception {
    // Prepare an artifact to be copied.
    FreeStyleProject copiee = j.createFreeStyleProject();
    copiee.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
    copiee.getPublishersList().add(new ArtifactArchiver("artifact.txt"));
    j.assertBuildStatusSuccess(copiee.scheduleBuild2(0));

    WorkflowJob copier = createWorkflowJob();
    copier.setDefinition(
        new CpsFlowDefinition(
            String.format(
                "node {"
                    + "step([$class: 'CopyArtifact',"
                    + "projectName: '%1$s',"
                    + "filter: '**/*',"
                    + "selector: [$class: 'ParameterizedBuildSelector', parameterName: 'SELECTOR'],"
                    + "]);"
                    + "step([$class: 'ArtifactArchiver', artifacts: '**/*']);"
                    + "}",
                copiee.getFullName()),
            true));

    WorkflowRun b =
        j.assertBuildStatusSuccess(
            copier.scheduleBuild2(
                0,
                null,
                new ParametersAction(
                    new StringParameterValue(
                        "SELECTOR",
                        "<StatusBuildSelector><stable>true</stable></StatusBuildSelector>"))));

    VirtualFile vf = b.getArtifactManager().root().child("artifact.txt");
    assertEquals("foobar", IOUtils.toString(vf.open()));
  }