Help with using the scripts int he vars directory of shared libraries

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Help with using the scripts int he vars directory of shared libraries

ZillaYT
I'm writing share libraries by following Extending with Shared Libraries, and I have a simple example working.

I now have created a script in the vars directory called debugger.groovy, that has a class definition, like this

class MyDebugger {
 
def logError(String msg) {
     log
("ERROR", msg)
 
}
 
...
 
private def log(String msgType, String msg) {
   
String m = "$msgType: $msg"
 
}
}

MyDebugger getDebuggerObj() {
 
return (new MyDebugger)
}


Now I have a script in my src/com/company directory called Deployer.groovy, and I want to use above MyDebugger like this because I want to use the same MyDebugger object all throughout my script.

package com.company.deployment

class MyDeployer {
 
def dbgObj = debugger.getDebuggerObj()
}

def deploy() {
 
Deployer d = new MyDeployer()
}


When I run it in my Jenkins pipeline, like this

pipeline {
  agent
{ label 'linux-devops' }
  stages
{
    stage
('build') {
      steps
{
        script
{
         
// This is the Library configured in Jenkins main configuratin page
         
@Library('my-library')
         
def deployer = new com.zift.deployment.Deployer()
          deployer
.deploy()
       
}
     
}
   
}
 
}




But I get

infrastructure/src/com/zift/deployment/EcsClusterBuilder.groovy: 9: Apparent variable 'debugger' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'debugger' but left out brackets in a place not allowed by the grammar.

 What's a better approach? I still want to keep the degugger.groovy structure, but am flexible on the Deployer.groovy script.

Thanks!

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a2238ee5-12ff-4134-b62f-637ee6f72054%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.