hudson.tasks.Publisher Java Examples

The following examples show how to use hudson.tasks.Publisher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecretBuildWrapperTest.java    From credentials-binding-plugin with MIT License 6 votes vote down vote up
@Issue("SECURITY-1374")
@Test public void maskingPostBuild() throws Exception {
    String credentialsId = "creds_1";
    String password = "p4$$";
    StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample1", Secret.fromString(password));

    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);

    SecretBuildWrapper wrapper = new SecretBuildWrapper(Collections.singletonList(new StringBinding("PASS_1", credentialsId)));

    FreeStyleProject f = r.createFreeStyleProject();

    f.setConcurrentBuild(true);
    f.getBuildWrappersList().add(wrapper);
    Publisher publisher = new PasswordPublisher(password);
    f.getPublishersList().add(publisher);

    FreeStyleBuild b = r.buildAndAssertSuccess(f);
    r.assertLogNotContains(password, b);
    r.assertLogContains("****", b);
}
 
Example #2
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the issue recorder instance for the specified job.
 *
 * @param job
 *         the job to get the recorder for
 *
 * @return the issue recorder
 */
protected IssuesRecorder getRecorder(final AbstractProject<?, ?> job) {
    DescribableList<Publisher, Descriptor<Publisher>> publishers = job.getPublishersList();
    for (Publisher publisher : publishers) {
        if (publisher instanceof IssuesRecorder) {
            return (IssuesRecorder) publisher;
        }
    }
    throw new AssertionError("No instance of IssuesRecorder found for job " + job);
}
 
Example #3
Source File: ViolationsToGitHubDescriptor.java    From violation-comments-to-github-plugin with MIT License 5 votes vote down vote up
@Override
public Publisher newInstance(final StaplerRequest req, @NonNull final JSONObject formData)
    throws hudson.model.Descriptor.FormException {
  assert req != null;
  if (formData.has("config")) {
    final JSONObject config = formData.getJSONObject("config");
    final String minSeverity = config.getString(FIELD_MINSEVERITY);
    if (StringUtils.isBlank(minSeverity)) {
      config.remove(FIELD_MINSEVERITY);
    }
  }

  return req.bindJSON(ViolationsToGitHubRecorder.class, formData);
}
 
Example #4
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Performs a configuration round-trip testing for a publisher.
 */
public <P extends Publisher> P configRoundtrip(P before) throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    p.getPublishersList().add(before);
    configRoundtrip((Item) p);
    return (P)p.getPublishersList().get(before.getClass());
}
 
Example #5
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Performs a configuration round-trip testing for a publisher.
 */
@SuppressWarnings("unchecked")
protected <P extends Publisher> P configRoundtrip(P before) throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    p.getPublishersList().add(before);
    configRoundtrip((Item) p);
    return (P)p.getPublishersList().get(before.getClass());
}
 
Example #6
Source File: TestNotifier.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
    return new BuildStepDescriptor<Publisher>() {
        @Override
        public boolean isApplicable(Class<? extends AbstractProject> jobType) {
            return true;
        }
    };
}
 
Example #7
Source File: JobDslITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a freestyle job from a YAML file and verifies that issue recorder finds warnings.
 */
@Test
public void shouldCreateFreestyleJobUsingJobDslAndVerifyIssueRecorderWithDefaultConfiguration() {
    configureJenkins("job-dsl-warnings-ng-default.yaml");

    TopLevelItem project = getJenkins().jenkins.getItem("dsl-freestyle-job");

    assertThat(project).isNotNull();
    assertThat(project).isInstanceOf(FreeStyleProject.class);

    DescribableList<Publisher, Descriptor<Publisher>> publishers = ((FreeStyleProject) project).getPublishersList();
    assertThat(publishers).hasSize(1);

    Publisher publisher = publishers.get(0);
    assertThat(publisher).isInstanceOf(IssuesRecorder.class);

    HealthReport healthReport = ((FreeStyleProject) project).getBuildHealth();
    assertThat(healthReport.getScore()).isEqualTo(100);

    IssuesRecorder recorder = (IssuesRecorder) publisher;

    assertThat(recorder.getAggregatingResults()).isFalse();
    assertThat(recorder.getTrendChartType()).isEqualTo(TrendChartType.AGGREGATION_TOOLS);
    assertThat(recorder.getBlameDisabled()).isFalse();
    assertThat(recorder.getForensicsDisabled()).isFalse();
    assertThat(recorder.getEnabledForFailure()).isFalse();
    assertThat(recorder.getHealthy()).isEqualTo(0);
    assertThat(recorder.getId()).isNull();
    assertThat(recorder.getIgnoreFailedBuilds()).isTrue();
    assertThat(recorder.getIgnoreQualityGate()).isFalse();
    assertThat(recorder.getMinimumSeverity()).isEqualTo("LOW");
    assertThat(recorder.getName()).isNull();
    assertThat(recorder.getQualityGates()).hasSize(0);
    assertThat(recorder.getSourceCodeEncoding()).isEmpty();
    assertThat(recorder.getUnhealthy()).isEqualTo(0);

    List<Tool> tools = recorder.getTools();
    assertThat(tools).hasSize(2);
    assertThat(tools.get(0)).isInstanceOf(Java.class);
}
 
Example #8
Source File: DslIntegrationTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
private void verifyPublishers(DescribableList<Publisher, Descriptor<Publisher>> publishers) {
    assertThat("Should add publisher", publishers, hasSize(2));

    assertThat("Should add status publisher", publishers.get(0), instanceOf(GitHubPRBuildStatusPublisher.class));
    assertThat("Should add 2 packages",
            ((GitHubPRBuildStatusPublisher) publishers.get(0)).getStatusMsg().getContent(),
            equalTo(JOB_DSL_PUBLISHER_TEXT_CONTENT));

    assertThat("Has comment publisher", publishers.get(1), instanceOf(GitHubPRCommentPublisher.class));
    GitHubPRCommentPublisher commentPublisher = (GitHubPRCommentPublisher) publishers.get(1);

    assertThat("Comment matches", commentPublisher.getComment().getContent(), equalTo("comment"));
    assertThat("Only failed builds", commentPublisher.getStatusVerifier().getBuildStatus(), equalTo(Result.FAILURE));
    assertThat("Publish marked as failure", commentPublisher.getErrorHandler().getBuildStatus(), equalTo(Result.FAILURE));
}
 
Example #9
Source File: ViolationsToBitbucketServerDescriptor.java    From violation-comments-to-stash-plugin with MIT License 5 votes vote down vote up
@Override
public Publisher newInstance(final StaplerRequest req, @NonNull final JSONObject formData)
    throws hudson.model.Descriptor.FormException {
  assert req != null;
  if (formData.has("config")) {
    final JSONObject config = formData.getJSONObject("config");
    final String minSeverity = config.getString(FIELD_MINSEVERITY);
    if (StringUtils.isBlank(minSeverity)) {
      config.remove(FIELD_MINSEVERITY);
    }
  }

  return req.bindJSON(ViolationsToBitbucketServerRecorder.class, formData);
}
 
Example #10
Source File: MattermostListener.java    From jenkins-mattermost-plugin with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
FineGrainedNotifier getNotifier(AbstractProject project, TaskListener listener) {
  Map<Descriptor<Publisher>, Publisher> map = project.getPublishersList().toMap();
  for (Publisher publisher : map.values()) {
    if (publisher instanceof MattermostNotifier) {
      return new ActiveNotifier((MattermostNotifier) publisher, (BuildListener) listener, new JenkinsTokenExpander(listener));
    }
  }
  return new DisabledNotifier();
}
 
Example #11
Source File: MattermostNotifier.java    From jenkins-mattermost-plugin with MIT License 5 votes vote down vote up
@Override
public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
  if (startNotification) {
    Map<Descriptor<Publisher>, Publisher> map = build.getProject().getPublishersList().toMap();
    JenkinsTokenExpander tokenExpander = new JenkinsTokenExpander(listener);
    for (Publisher publisher : map.values()) {
      if (publisher instanceof MattermostNotifier) {
        logger.info("Invoking Started...");
        new ActiveNotifier((MattermostNotifier) publisher, listener, tokenExpander).started(build);
      }
    }
  }
  return super.prebuild(build, listener);
}
 
Example #12
Source File: GitChangelogRecorder.java    From git-changelog-plugin with MIT License 4 votes vote down vote up
@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
  return DESCRIPTOR;
}
 
Example #13
Source File: DotCiExtensionsHelper.java    From DotCi with MIT License 4 votes vote down vote up
private ArrayList<Descriptor<?>> getDescriptors() {
    ArrayList<Descriptor<?>> r = new ArrayList<Descriptor<?>>();
    r.addAll(getClassList(Builder.class));
    r.addAll(getClassList(Publisher.class));
    return r;
}
 
Example #14
Source File: JUnitFlakyResultArchiver.java    From flaky-test-handler-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher
newInstance(StaplerRequest req, JSONObject formData)
    throws hudson.model.Descriptor.FormException {
  return new JUnitFlakyResultArchiver();
}
 
Example #15
Source File: TestUtils.java    From phabricator-jenkins-plugin with MIT License 4 votes vote down vote up
public static Publisher getDefaultXUnitPublisher() {
    return new JUnitResultArchiver(
            JUNIT_XML
    );
}
 
Example #16
Source File: ViolationsToBitbucketServerRecorder.java    From violation-comments-to-stash-plugin with MIT License 4 votes vote down vote up
@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
  return DESCRIPTOR;
}
 
Example #17
Source File: GitChangelogDescriptor.java    From git-changelog-plugin with MIT License 4 votes vote down vote up
@Override
public Publisher newInstance(final StaplerRequest req, final JSONObject formData)
    throws hudson.model.Descriptor.FormException {
  final GitChangelogConfig c = new GitChangelogConfig();
  c.setUseConfigFile(formData.getBoolean("useConfigFile"));
  c.setConfigFile(formData.getString("configFile"));
  c.setFromType(formData.getString("fromType"));
  c.setFromReference(formData.getString("fromReference"));
  c.setToType(formData.getString("toType"));
  c.setUseSubDirectory(formData.getBoolean("useSubDirectory"));
  c.setSubDirectory(formData.getString("subDirectory"));
  c.setToReference(formData.getString("toReference"));
  c.setDateFormat(formData.getString("dateFormat"));
  c.setTimeZone(formData.getString("timeZone"));
  c.setIgnoreCommitsIfMessageMatches(formData.getString("ignoreCommitsIfMessageMatches"));
  c.setUseIgnoreTagsIfNameMatches(formData.getBoolean("useIgnoreTagsIfNameMatches"));
  c.setIgnoreTagsIfNameMatches(formData.getString("ignoreTagsIfNameMatches"));

  c.setUseJira(formData.getBoolean("useJira"));
  c.setJiraServer(formData.getString("jiraServer"));
  c.setJiraIssuePattern(formData.getString("jiraIssuePattern"));
  c.setJiraUsernamePasswordCredentialsId(formData.getString("jiraUsernamePasswordCredentialsId"));
  c.setJiraBasicAuthStringCredentialsId(formData.getString("jiraBasicAuthStringCredentialsId"));

  c.setUseGitHub(formData.getBoolean("useGitHub"));
  c.setGitHubApi(formData.getString("gitHubApi"));
  c.setGitHubIssuePattern(formData.getString("gitHubIssuePattern"));
  c.setGitHubApiTokenCredentialsId(formData.getString("gitHubApiTokenCredentialsId"));

  c.setUseGitLab(formData.getBoolean("useGitLab"));
  c.setGitLabServer(formData.getString("gitLabServer"));
  c.setGitLabProjectName(formData.getString("gitLabProjectName"));
  c.setGitLabApiTokenCredentialsId(formData.getString("gitLabApiTokenCredentialsId"));

  c.setNoIssueName(formData.getString("noIssueName"));
  c.setIgnoreCommitsWithoutIssue(formData.getBoolean("ignoreCommitsWithoutIssue"));
  c.setUntaggedName(formData.getString("untaggedName"));
  c.setUseReadableTagName(formData.getBoolean("useReadableTagName"));
  c.setReadableTagName(formData.getString("readableTagName"));
  c.setUseFile(formData.getBoolean("useFile"));
  c.setFile(formData.getString("file"));
  c.setShowSummary(formData.getBoolean("showSummary"));

  c.setCreateFileUseTemplateFile(formData.getBoolean("createFileUseTemplateFile"));
  c.setCreateFileTemplateFile(formData.getString("createFileTemplateFile"));
  c.setCreateFileUseTemplateContent(formData.getBoolean("createFileUseTemplateContent"));
  c.setCreateFileTemplateContent(formData.getString("createFileTemplateContent"));

  c.setShowSummaryUseTemplateFile(formData.getBoolean("showSummaryUseTemplateFile"));
  c.setShowSummaryTemplateFile(formData.getString("showSummaryTemplateFile"));
  c.setShowSummaryUseTemplateContent(formData.getBoolean("showSummaryUseTemplateContent"));
  c.setShowSummaryTemplateContent(formData.getString("showSummaryTemplateContent"));

  c.setCustomIssues(new ArrayList<>());
  if (formData.containsKey("name")) {
    for (int i = 0; i < formData.getJSONArray("name").size(); i++) {
      final String name = (String) formData.getJSONArray("name").get(i);
      final String pattern = (String) formData.getJSONArray("pattern").get(i);
      final String link = (String) formData.getJSONArray("link").get(i);
      final String title = (String) formData.getJSONArray("title").get(i);
      if (!isNullOrEmpty(name) && !isNullOrEmpty(pattern)) {
        c.getCustomIssues().add(new CustomIssue(name, pattern, link, title));
      }
    }
  }
  c.getCustomIssues().add(new CustomIssue("", "", "", ""));
  c.getCustomIssues().add(new CustomIssue("", "", "", ""));

  final GitChangelogRecorder publisher = new GitChangelogRecorder();
  publisher.setConfig(c);
  return publisher;
}
 
Example #18
Source File: ViolationsToGitHubRecorder.java    From violation-comments-to-github-plugin with MIT License 4 votes vote down vote up
@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
  return DESCRIPTOR;
}
 
Example #19
Source File: JobDslITest.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
/**
 * Creates a freestyle job from a YAML file and verifies that all fields in issue recorder are set correct.
 */
@Test
public void shouldCreateFreestyleJobUsingJobDslAndVerifyIssueRecorderWithValuesSet() {
    configureJenkins("job-dsl-warnings-ng.yaml");

    TopLevelItem project = getJenkins().jenkins.getItem("dsl-freestyle-job");

    assertThat(project).isNotNull();
    assertThat(project).isInstanceOf(FreeStyleProject.class);

    DescribableList<Publisher, Descriptor<Publisher>> publishers = ((FreeStyleProject) project).getPublishersList();
    assertThat(publishers).hasSize(1);

    Publisher publisher = publishers.get(0);
    assertThat(publisher).isInstanceOf(IssuesRecorder.class);

    HealthReport healthReport = ((FreeStyleProject) project).getBuildHealth();
    assertThat(healthReport.getScore()).isEqualTo(100);

    IssuesRecorder recorder = (IssuesRecorder) publisher;

    assertThat(recorder.getAggregatingResults()).isTrue();
    assertThat(recorder.getTrendChartType()).isEqualTo(TrendChartType.NONE);
    assertThat(recorder.getBlameDisabled()).isTrue();
    assertThat(recorder.getForensicsDisabled()).isTrue();
    assertThat(recorder.getEnabledForFailure()).isTrue();
    assertThat(recorder.getHealthy()).isEqualTo(10);
    assertThat(recorder.getId()).isEqualTo("test-id");
    assertThat(recorder.getIgnoreFailedBuilds()).isFalse();
    assertThat(recorder.getIgnoreQualityGate()).isTrue();
    assertThat(recorder.getMinimumSeverity()).isEqualTo("ERROR");
    assertThat(recorder.getName()).isEqualTo("test-name");
    assertThat(recorder.getSourceCodeEncoding()).isEqualTo("UTF-8");
    assertThat(recorder.getUnhealthy()).isEqualTo(50);
    assertThat(recorder.getReferenceJobName()).isEqualTo("test-job");
    assertThat(recorder.getQualityGates()).hasSize(1);

    List<Tool> tools = recorder.getTools();
    assertThat(tools).hasSize(2);
    assertThat(tools.get(0)).isInstanceOf(Java.class);

}