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

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

      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.

          [JENKINS-31229] Flexible publisher does not properly consider 'dynamic' RunCondition for MatrixBuild aggregation

          Frédéric Chuong created issue -
          ikedam made changes -
          Assignee Original: bap [ bap ] New: ikedam [ ikedam ]

          ikedam added a comment -

          The condition is evaluated only once when a build starts.
          It decides whether to run all the aggregation process including

          • startBuild: called when a parent build start.
          • endRun: called when a each child finishes.
          • endBuild: called when a parent build finishes.

          This also means a following problem: you cannot use axes values in conditions for aggregation.
          I'll consoder to add an options for each steps.

          ikedam added a comment - The condition is evaluated only once when a build starts. It decides whether to run all the aggregation process including startBuild: called when a parent build start. endRun: called when a each child finishes. endBuild: called when a parent build finishes. This also means a following problem: you cannot use axes values in conditions for aggregation. I'll consoder to add an options for each steps.
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 166458 ] New: JNJira + In-Review [ 182391 ]

          ikedam added a comment -

          This plugin is now out for adoption.

          ikedam added a comment - This plugin is now out for adoption.
          ikedam made changes -
          Assignee Original: ikedam [ ikedam ]

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

              Created:
              Updated: