Re: Jenkins2 pipeline - Global methods in shared-library fails when invoked

2017-02-02 Thread David Karr
On Thursday, February 2, 2017 at 2:13:36 PM UTC-8, Daniel Beck wrote:
>
>
> > On 02.02.2017, at 17:27, David Karr  
> wrote: 
> > 
> > Wow, and the documentation page doesn't even MENTION this fact?  I'm 
> reading it now, and there's that underscore, completely without any 
> statement like YES, THIS REALLY NEEDS TO BE HERE.  Seriously? 
>
> Could you clarify what you're referring to? Tor Christian quoted the 
> documentation which states… 
>
> > For Shared Libraries which only define Global Variables (vars/), or a 
> Jenkinsfile which only needs a Global Variable, the 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. 
>
>
>
I perhaps phrased that stronger than it should have. However, the example 
that comes before this text uses the underscore character without 
mentioning it.  It's only this note that comes a few lines later on when 
this is mentioned. When I first wrote that reply (I did try to delete it), 
I saw the example without any explanation, and didn't notice the 
explanation until later.

-- 
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/318779d6-87fc-4edb-9f9b-1ed45a37bb8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins2 pipeline - Global methods in shared-library fails when invoked

2017-02-02 Thread Daniel Beck

> On 02.02.2017, at 17:27, David Karr  wrote:
> 
> Wow, and the documentation page doesn't even MENTION this fact?  I'm reading 
> it now, and there's that underscore, completely without any statement like 
> YES, THIS REALLY NEEDS TO BE HERE.  Seriously?

Could you clarify what you're referring to? Tor Christian quoted the 
documentation which states…

> For Shared Libraries which only define Global Variables (vars/), or a 
> Jenkinsfile which only needs a Global Variable, the 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.


-- 
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/90C8402F-BA1C-47F1-BD74-DE22FC7EB7E3%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins2 pipeline - Global methods in shared-library fails when invoked

2017-02-02 Thread David Karr
On Thursday, February 2, 2017 at 3:30:05 AM UTC-8, R Tyler Croy wrote:
>
> (replies inline) 
>
> On Thu, 02 Feb 2017, Tor Christian Solev?gseide wrote: 
>
> > 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): 
>
>
> FWIW, the underscore character is kind of a cute little hack. @Library is 
> an 
> annotation so it must annotate *something*, annotating the underscore is 
> kind 
> of like annotating a throwaway unused character. Technically you're able 
> to 
> annotate other statements, as the section in the handbook describes 
>

Wow, and the documentation page doesn't even MENTION this fact?  I'm 
reading it now, and there's that underscore, completely without any 
statement like YES, THIS REALLY NEEDS TO BE HERE.  Seriously?
 

>
>
> - R. Tyler Croy 
>
> -- 
>  Code:  
>   Chatter:  
>  xmpp: rty...@jabber.org  
>
>   % gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F 
> -- 
>

-- 
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/f0014c4e-2d77-4372-bf65-817b08b02b7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins2 pipeline - Global methods in shared-library fails when invoked

2017-02-02 Thread R. Tyler Croy
(replies inline)

On Thu, 02 Feb 2017, Tor Christian Solev?gseide wrote:

> 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):


FWIW, the underscore character is kind of a cute little hack. @Library is an
annotation so it must annotate *something*, annotating the underscore is kind
of like annotating a throwaway unused character. Technically you're able to
annotate other statements, as the section in the handbook describes


- R. Tyler Croy

--
 Code: 
  Chatter: 
 xmpp: rty...@jabber.org

  % gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F
--

-- 
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/20170202112955.GJ26439%40blackberry.coupleofllamas.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Jenkins2 pipeline - Global methods in shared-library fails when invoked

2017-02-02 Thread Tor Christian Solevågseide
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 
>  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.


Jenkins2 pipeline - Global methods in shared-library fails when invoked

2017-01-20 Thread Tor Christian Solevågseide
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/4ea660e5-672e-404d-b0d3-d8733878221d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.