Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-38788

Added publishers may fail depending on the add order

XMLWordPrintable

      Consider the following test:

      public class PublisherOrderTest extends AbstractJUnitTest {
      
          @Test
          public void testOrdered() {
              FreeStyleJob upstream = jenkins.jobs.create(FreeStyleJob.class);
              upstream.configure();
              String command = "echo 'hello' > aggregate.txt";
              if(SystemUtils.IS_OS_UNIX) {
                  upstream.addShellStep(command);
              } else {
                  upstream.addBatchStep(command);
              }
              AggregateDownstreamTestResults aggregate = upstream.addPublisher(AggregateDownstreamTestResults.class);
              aggregate.specify.check();
              ArtifactArchiver archiver = upstream.addPublisher(ArtifactArchiver.class);
              archiver.includes("aggregate.txt");
              BuildTrigger trigger = upstream.addPublisher(BuildTrigger.class);
              trigger.childProjects.set("projectName");
              Fingerprint fingerprint = upstream.addPublisher(Fingerprint.class);
              fingerprint.targets.set("aggregate.txt");
              upstream.save();
          }
      
          @Test
          public void testUnordered() {
              FreeStyleJob upstream = jenkins.jobs.create(FreeStyleJob.class);
              upstream.configure();
              String command = "echo 'hello' > aggregate.txt";
              if(SystemUtils.IS_OS_UNIX) {
                  upstream.addShellStep(command);
              } else {
                  upstream.addBatchStep(command);
              }
              ArtifactArchiver archiver = upstream.addPublisher(ArtifactArchiver.class);
              archiver.includes("aggregate.txt");
              BuildTrigger trigger = upstream.addPublisher(BuildTrigger.class);
              trigger.childProjects.set("projectName");
              Fingerprint fingerprint = upstream.addPublisher(Fingerprint.class);
              fingerprint.targets.set("aggregate.txt");
              AggregateDownstreamTestResults aggregate = upstream.addPublisher(AggregateDownstreamTestResults.class);
              aggregate.specify.check();
              upstream.save();
          }
      

      The second test fails on Jenkins because the `Job.addStep' method expects Publishers to be added as a queue (FIFO order) whilst they seem to be ordered alphabetically on the UI.

      An easy workaround for tests is to add the Publishers alphabetically, but that does not seem a real simulation of a test case, where users can add publishers on any order

            rarabaolaza Raul Arabaolaza
            rarabaolaza Raul Arabaolaza
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: