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

PostBuild declarative validator called twice

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I am hoping to extend the Declarative Model Validator to provide linting services that have the team's policies / standards integrated. Working on a validator for ModelASTPostBuild I saw that the validator was being called twice.

       

      My extension:

      @Extension
      public class PostBuildValidator extends DeclarativeValidatorContributor {
      
          @CheckForNull
          @Override
          public String validateElement(@Nonnull ModelASTPostBuild postBuild, @CheckForNull FlowExecution execution) {
              return "abc" + postBuild.getName();
          }
      }
      

      My jenkinsfile:

      pipeline {
        agent {
          label 'unix'
        }
        stages {
          stage('test'){
            steps{
              echo "test"
            }
          }
        }
        post {
          always{
            echo "cleaning"
            deleteDir()
          }
        }
      }
      

      Response from pipeline-model-converter/validateJenkinsfile:

      {"status":"ok","data":{"result":"failure","errors":[

      {"error":["abcpost @ line 12, column 3.","abcpost @ line 12, column 3."]}

      ]}}

        Attachments

          Issue Links

            Activity

            stevenfoster Steven Foster created issue -
            stevenfoster Steven Foster made changes -
            Field Original Value New Value
            Description I am hoping to extend the Declarative Model Validator to provide linting services that have the team's policies / "style" integrated. Working on a validator for ModelASTPostBuild I saw that the validator was being called twice.

             

            My extension:
            {code:java}
            @Extension
            public class PostBuildValidator extends DeclarativeValidatorContributor {

                @CheckForNull
                @Override
                public String validateElement(@Nonnull ModelASTPostBuild postBuild, @CheckForNull FlowExecution execution) {
                    return "abc" + postBuild.getName();
                }
            }
            {code}

            My jenkinsfile:

            {code:java}
            pipeline {
              agent {
                label 'unix'
              }
              stages {
                stage('test'){
                  steps{
                    echo "test"
                  }
                }
              }
              post {
                always{
                  echo "cleaning"
                  deleteDir()
                }
              }
            }
            {code}

            Response from pipeline-model-converter/validateJenkinsfile:

            {"status":"ok","data":{"result":"failure","errors":[{"error":["abcpost @ line 12, column 3.","abcpost @ line 12, column 3."]}]}}
            I am hoping to extend the Declarative Model Validator to provide linting services that have the team's policies / standards integrated. Working on a validator for ModelASTPostBuild I saw that the validator was being called twice.

             

            My extension:
            {code:java}
            @Extension
            public class PostBuildValidator extends DeclarativeValidatorContributor {

                @CheckForNull
                @Override
                public String validateElement(@Nonnull ModelASTPostBuild postBuild, @CheckForNull FlowExecution execution) {
                    return "abc" + postBuild.getName();
                }
            }
            {code}

            My jenkinsfile:

            {code:java}
            pipeline {
              agent {
                label 'unix'
              }
              stages {
                stage('test'){
                  steps{
                    echo "test"
                  }
                }
              }
              post {
                always{
                  echo "cleaning"
                  deleteDir()
                }
              }
            }
            {code}

            Response from pipeline-model-converter/validateJenkinsfile:

            {"status":"ok","data":{"result":"failure","errors":[{"error":["abcpost @ line 12, column 3.","abcpost @ line 12, column 3."]}]}}
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Hide
            abayer Andrew Bayer added a comment -

            Think I found it. Verifying now.

            Show
            abayer Andrew Bayer added a comment - Think I found it. Verifying now.
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            Show
            abayer Andrew Bayer added a comment - Got it! PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/213
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "PR #213 (Web Link)" [ 17989 ]
            Hide
            stevenfoster Steven Foster added a comment -

            Finding the same behaviour for ModelASTOption validator, need a separate ticket?

            Show
            stevenfoster Steven Foster added a comment - Finding the same behaviour for ModelASTOption validator, need a separate ticket?
            Hide
            stevenfoster Steven Foster added a comment -

            The duplication is from public boolean validateElement(@Nonnull ModelASTMethodCall meth), I suppose that is intentional and I should just differentiate them somehow

            Show
            stevenfoster Steven Foster added a comment - The duplication is from public boolean validateElement(@Nonnull ModelASTMethodCall meth), I suppose that is intentional and I should just differentiate them somehow
            Hide
            abayer Andrew Bayer added a comment -

            Nah, that’s on me, I’ll clean it up in the same PR.

            Show
            abayer Andrew Bayer added a comment - Nah, that’s on me, I’ll clean it up in the same PR.
            Hide
            abayer Andrew Bayer added a comment -

            And updated. Double checking now to make sure I don't have any other cases of super.validate calls like with ModelASTBuildConditionsContainer and ModelASTMethodCall that are double calling validateFromContributors...

            Show
            abayer Andrew Bayer added a comment - And updated. Double checking now to make sure I don't have any other cases of super.validate calls like with ModelASTBuildConditionsContainer and ModelASTMethodCall that are double calling validateFromContributors ...
            Hide
            abayer Andrew Bayer added a comment -

            Only other case was ModelASTTreeStep, which doesn't have its own validateElement method in the first place, so we should be all good.

            Show
            abayer Andrew Bayer added a comment - Only other case was ModelASTTreeStep , which doesn't have its own validateElement method in the first place, so we should be all good.
            Hide
            abayer Andrew Bayer added a comment -

            Will be in next release (1.2.4).

            Show
            abayer Andrew Bayer added a comment - Will be in next release (1.2.4).
            abayer Andrew Bayer made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
            pipeline-model-definition/src/test/resources/errors/postValidatorContributor.groovy
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/f3d3486038c985a8f938f0f9da735c2839903dbd
            Log:
            [FIXED JENKINS-47814] Don't run post validator contirbutors twice

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java pipeline-model-definition/src/test/resources/errors/postValidatorContributor.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/f3d3486038c985a8f938f0f9da735c2839903dbd Log: [FIXED JENKINS-47814] Don't run post validator contirbutors twice

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                stevenfoster Steven Foster
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: