while the following works fine:

      @Library('yooture') 
      import yooture.jenkins.yooture.Yooture
      
      def yoo = new Yooture()
      node {
          yoo.sendChatMessage("hello")
      }
      

      the same definition of a utility library does not work when used in a pipeline model definition:

      @Library('yooture') 
      import yooture.jenkins.yooture.Yooture
      
      def yoo = new Yooture()
      
      pipeline {
        agent any
        stages {
          stage ('prepare') {
            steps {
              script {
                  yoo.sendChatMessage("hello")
              }
            }
          }
        }
      }
      

      it fails with:

       > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
       > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
      Checking out Revision 925b9e05a9e0f6e9717275ad8215e9f07714f38b (refs/remotes/origin/master)
       > 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:
      WorkflowScript: 1: unable to resolve class Library ,  unable to find class for annotation
       @ line 1, column 1.
         @Library('yooture') 
         ^
      
      1 error
      
      	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)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:497)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
      	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:206)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter.scriptToPipelineDef(Converter.groovy:116)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter.parseFromCpsScript(Converter.groovy:177)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter$parseFromCpsScript.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter$parseFromCpsScript.call(Unknown Source)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils.attachExecutionModel(Utils.groovy:183)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils$attachExecutionModel.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/home/yooture/hudson_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:52)
      	at WorkflowScript.run(WorkflowScript:7)
      	at ___cps.transform___(Native Method)
      

          [JENKINS-40640] @Library not working with pipeline model

          Andrew Bayer added a comment -

          Folding this in with JENKINS-40642 since it'll be the same fix.

          Andrew Bayer added a comment - Folding this in with JENKINS-40642 since it'll be the same fix.

          Liam Newman added a comment -

          Bulk closing resolved issues.

          Liam Newman added a comment - Bulk closing resolved issues.

          The issue is reproducible in Jenkins ver. 2.204.2 too, Is this really a duplicate for JENKINS-40642?

          Prabhu Shankar added a comment - The issue is reproducible in Jenkins ver. 2.204.2 too, Is this really a duplicate for JENKINS-40642 ?

          I can replicate the same problem on 2.225 with a very basic script:
           

          package com.something
          
          class Foo {
              def helloWorld() {
                  echo "Hello World!"
              }
          }
          

          and then

          @Library('global-library')
          import com.something.Foo
          

          throws the error.

          At the same time importing from vars/ using

          @Library('global-library') _
          

          works fine

          Igor Stojanovski added a comment - I can replicate the same problem on 2.225 with a very basic script:   package com.something class Foo { def helloWorld() { echo "Hello World!" } } and then @Library( 'global-library' ) import com.something.Foo throws the error. At the same time importing from vars/ using @Library( 'global-library' ) _ works fine

          Charles Moulliard added a comment - - edited

          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') _
          ....

          Charles Moulliard added a comment - - edited 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' ) _ ....

            Unassigned Unassigned
            imod Dominik Bartholdi
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: