I was finally able to solve this myself. The problem was how I referenced 
the shared library. Apparently, I need to add the underscore character to 
the end if my @Library annotation like this:
@Library('customized-portal-lib') _

Also, I must make sure to not import my global *acme *variable.

This is documented 
in https://jenkins.io/doc/book/pipeline/shared-libraries/ for those who 
take their time to fine read it (which I didn't at first):

> For Shared Libraries which only define Global Variables (vars/), or a 
> Jenkinsfile which only needs a Global Variable, the annotation 
> <http://groovy-lang.org/objectorientation.html#_annotation> pattern 
> @Library('my-shared-library') 
> _ may be useful for keeping code concise. In essence, instead of 
> annotating an unnecessary import statement, the symbol _ is annotated.
>
 

> It is not recommended to import a global variable/function, since this 
> will force the compiler to interpret fields and methods as static even if 
> they were intended to be instance. The Groovy compiler in this case can 
> produce confusing error messages.


/TC


fredag 20. januar 2017 12.24.21 UTC+1 skrev Tor Christian Solevågseide 
følgende:
>
> As documented in https://jenkins.io/doc/book/pipeline/shared-libraries/, 
> I've created the file vars/acme.groovy in a library project checked into 
> our SVN.
>
>
> def setName(value) {
>     this.name = value;
> }
> def getName() {
>     return this.name;
> }
> def caution(message) {
>     echo "Hello, ${this.name}! CAUTION: ${message}"
> }
>
>
>
>
> My pipeline script in a Jenkins2 pipeline project:
> acme.name = 'Alice'
> echo acme.name 
>
> acme.caution 'The queen is angry!'
>
>
>
>
> The two first lines, setting and getting the name works fine.
> But when I include the last line, calling the "caution" function the 
> script fails with
>
>
> hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No 
> signature of method: static Alice.caution() is applicable for argument 
> types: (java.lang.String) values: [The queen is angry!]
> Possible solutions: caution(java.lang.Object), wait(), 
> main([Ljava.lang.String;)
> at 
> groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1503)
> at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1489)
> at 
> org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)
> 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 WorkflowScript.run(WorkflowScript:8)
>
>
>
> If I remove the first 2 lines of the pipeline script, leaving only the 
> "acme.caution" call, the error detail is changed to
>
> hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No 
> signature of method: static acme.caution() is applicable for argument types: 
> (java.lang.String) values: [The queen is angry!]
>
>
>
> Jenkins version 2.41
> Pipeline plugin 2.4
>
>
> Any idea what's going on here?  Feels like a bug, or at least wrong doc...?
>
> regards
> Tor Christian Solevågseide
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c5863b80-60eb-465f-9b5c-ae7636d88c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to