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

Flexible publisher does not properly consider 'dynamic' RunCondition for MatrixBuild aggregation

XMLWordPrintable

      For MatrixProject, aggregation conditions seems to be only evaluated during the initial org.jenkins_ci.plugins.flexible_publish.FlexiblePublisher.createAggregator(MatrixBuild, Launcher, BuildListener) call.
      That is fine for static conditions (such as org.jenkins_ci.plugins.run_condition.common.PrebuildSameAsPerformRunCondition hierarchy) but that does not allow 'dynamic' conditions to behave as expected: the associated publishers will be executed if the initial state of the build met the condition, regardless of the dynamic nature of the build (which may have invalidated the RunCondition after createAggretator())

      The following unit test will fail if run against current code base f157d4ec81547934854b765a58eb5f03de64a388:

          public void testMatrixAggregationCondition() throws Exception {
              final MatrixProject p = createMatrixProject();
              p.setAxes(new AxisList(new TextAxis("axis1", "value1")));
      
              // have the build result set to UNSTABLE on purpose
              p.getBuildersList().add(new TestBuilder() {
                  @Override
                  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
                      build.setResult(Result.UNSTABLE);
                      return true;
                  }
                  @Override
                  public Descriptor<Builder> getDescriptor() {
                      return new Descriptor<Builder>() {
                          @Override
                          public String getDisplayName() {
                              return "Unstable builder";
                          }
                      };
                  }
              });
      
              // add a publisher with aggregation condition that cannot be met with above builder
              p.getPublishersList().add(new FlexiblePublisher(
                  Arrays.asList(
                      new ConditionalPublisher(
                          new NeverRun(),
                          Arrays.<BuildStep>asList(
                              new ThrowGeneralExceptionRecorder()
                          ),
                          new BuildStepRunner.Fail(),
                          true,
                          // should prevent publisher from running
                          new StatusCondition(Result.SUCCESS.toString(), Result.SUCCESS.toString()),
                          new BuildStepRunner.Fail(),
                          new FailFastExecutionStrategy()
                      )
                  )
              ));
              final MatrixBuild matrixBuild = p.scheduleBuild2(0).get();
      
              // assert that the publisher did not get executed and did not change status to FAILURE
              assertBuildStatus(Result.UNSTABLE, matrixBuild);
          }
      

      what is seen is that the publisher gets executed, failing the test.

            Unassigned Unassigned
            fchuong Frédéric Chuong
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: