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

@NonCPS and @Library not visible in utility classes when used in pipeline model

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      It seems that @NonCPS and @Library are not visible in the context of a pipeline model definition and must be fully qualified. ...but to be honest, I have no idea what FQN of this class is. In a "normal" pipeline script, this class is visible by default.

      the error I get is:

       > git config core.sparsecheckout # timeout=10
       > git checkout -f 925b9e05a9e0f6e9717275ad8215e9f07714f38b
       > git rev-list 925b9e05a9e0f6e9717275ad8215e9f07714f38b # timeout=10
      [Pipeline] End of Pipeline
      hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      file:/home/yooture/hudson_home/jobs/ci/jobs/dummy/builds/90/libs/yooture/src/yooture/jenkins/cloudfoundry/Cloudfoundry.groovy: 214: unable to resolve class NonCPS ,  unable to find class for annotation
       @ line 214, column 1.
         @NonCPS
         ^
      
      file:/home/yooture/hudson_home/jobs/ci/jobs/dummy/builds/90/libs/yooture/src/yooture/jenkins/cloudfoundry/Cloudfoundry.groovy: 220: unable to resolve class NonCPS ,  unable to find class for annotation
       @ line 220, column 1.
         @NonCPS
         ^
      
      2 errors
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      	at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:946)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:542)
      	at org.codehaus.groovy.control.CompilationUnit$compile$1.call(Unknown Source)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter.compilationUnitToPipelineDef(Converter.groovy:136)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Huh, that's dumb. I should be able to fix that easily.

            Show
            abayer Andrew Bayer added a comment - Huh, that's dumb. I should be able to fix that easily.
            Hide
            abayer Andrew Bayer added a comment -

            Can you get me a reproduction case? I've got a fix, I'm pretty sure, but I need a test. =)

            Show
            abayer Andrew Bayer added a comment - Can you get me a reproduction case? I've got a fix, I'm pretty sure, but I need a test. =)
            Hide
            abayer Andrew Bayer added a comment -

            Ah, with @Library added in, I've got a test case, so an initial PR is coming momentarily.

            Show
            abayer Andrew Bayer added a comment - Ah, with @Library added in, I've got a test case, so an initial PR is coming momentarily.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/pom.xml
            pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/Converter.groovy
            pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/GroovyShellDecoratorImpl.java
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
            pipeline-model-definition/src/test/resources/libraryAnnotation.groovy
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/29da05355dc0bcb543ce376bd07eefd39d8ca10d
            Log:
            [FIXED JENKINS-40642] Add additional imports for parse/translate

            @NonCPS and @Library were the most glaring missing import, but I
            replicated the standard CpsGroovyShell imports - @NonCPS's package,
            hudson.model, jenkins.model, and anything provided by a GroovyShellDecorator.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/pom.xml pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/Converter.groovy pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/GroovyShellDecoratorImpl.java pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java pipeline-model-definition/src/test/resources/libraryAnnotation.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/29da05355dc0bcb543ce376bd07eefd39d8ca10d Log: [FIXED JENKINS-40642] Add additional imports for parse/translate @NonCPS and @Library were the most glaring missing import, but I replicated the standard CpsGroovyShell imports - @NonCPS's package, hudson.model, jenkins.model, and anything provided by a GroovyShellDecorator.
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.
            Hide
            cmoulliard Charles Moulliard added a comment -

            I also experiment this issue using version 2.271 when I try to create a pipeline from a groovy cloned file using a Seed job = FreeStyleProject

            Processing DSL script pipelines/pipelineCheckBomDependencies.groovy
            ERROR: startup failed:
            pipelineCheckBomDependencies.groovy: 1: unable to resolve class org.jenkinsci.plugins.workflow.libs.Library ,  unable to find class for annotation
             @ line 1, column 1.
               @org.jenkinsci.plugins.workflow.libs.Library('snowdrop-lib@0.2') _
            
            or
            
            ERROR: startup failed:
            pipelineCheckBomDependencies.groovy: 2: unable to resolve class org.jenkinsci.plugins.workflow.libs.Library
             @ line 2, column 1.
               import org.jenkinsci.plugins.workflow.libs.Library

            Pipeline groovy file starts like this

            @org.jenkinsci.plugins.workflow.libs.Library('snowdrop-lib@0.2') _
            
            def AGENT_LABEL = null
            
            ...
            
            OR
            
            @Library('snowdrop-lib@0.2') _
            ....
            Show
            cmoulliard Charles Moulliard added a comment - I also experiment this issue using version 2.271 when I try to create a pipeline from a groovy cloned file using a Seed job = FreeStyleProject Processing DSL script pipelines/pipelineCheckBomDependencies.groovy ERROR: startup failed: pipelineCheckBomDependencies.groovy: 1: unable to resolve class org.jenkinsci.plugins.workflow.libs.Library , unable to find class for annotation @ line 1, column 1. @org.jenkinsci.plugins.workflow.libs.Library( 'snowdrop-lib@0.2' ) _ or ERROR: startup failed: pipelineCheckBomDependencies.groovy: 2: unable to resolve class org.jenkinsci.plugins.workflow.libs.Library @ line 2, column 1. import org.jenkinsci.plugins.workflow.libs.Library Pipeline groovy file starts like this @org.jenkinsci.plugins.workflow.libs.Library( 'snowdrop-lib@0.2' ) _ def AGENT_LABEL = null ... OR @Library( 'snowdrop-lib@0.2' ) _ ....

              People

              Assignee:
              abayer Andrew Bayer
              Reporter:
              imod Dominik Bartholdi
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: