0

I have an IniParser class that I want to use as coming from a shared library in Jenkins (because of DRY).

I tried putting the class in src/com/xxx/IniParser.groovy and accessing the class using the following code in my pipeline:

@Library('my-ini-parser') _
def parserObj = com.xxx.IniParser()

I also tried putting the class in vars folder and trying to access. No luck. Please propose a solution.

mkobit
  • 43,979
  • 12
  • 156
  • 150
Ciado
  • 1,996
  • 2
  • 17
  • 15
  • if your using declarative, maybe you need to use a script{} step? (Unsure I haven't used declarative before, only scripted which works as your example suggests) – metalisticpain Apr 04 '18 at 10:03
  • Yes, its declarative. I defined a function outside the pipeline {...} and writes the code there, – Ciado Apr 04 '18 at 10:36
  • Just create a git repo with a subfolder vars/, add your groovyscripts in vars/. Configure your shared library in global configuration of Jenkins and use the @Library('name-of-library-from-global-configuration') and you can access the .groovy functions in your repo. – lvthillo Apr 04 '18 at 11:04
  • I can and in fact have used functions in that manner, but this time, I need to store a class in the library. When I create a file with the class (and only the class) inside, then try to access it in the declarative pipeline, the following exception throws up and build goes to failure - `hudson.remoting.ProxyException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation` – Ciado Apr 04 '18 at 11:58
  • I don't believe you can have a package namespace for things in `vars`. – mkobit Apr 04 '18 at 13:39
  • If you are trying to define the shared library in the same repository, you should look at [this other Stack Overflow question](https://stackoverflow.com/questions/46213913/load-jenkins-pipeline-shared-library-from-same-repository/49112612#49112612). – mkobit Apr 04 '18 at 15:41
  • Can you add the IniParser.groovy code here? – metalisticpain Apr 04 '18 at 22:28

0 Answers0