1

I have developed groovy classes in IntelliJ IDE, I want to instantiate one of these classes in 'Pipeline script' of Pipeline plugin in Jenkins. I tried to follow the examples of 'Eval.me' and class.forName

Sample

package com.mycomp.tmo

/**
 * Created by
 */
public void callMe(){
    println("Hello World !")
}


def e = "callMe"
def cl = Class.forName("com.mycomp.tmo.Sample")
println(Eval.me("${c1} (${e})"))

Tried Below as well:

String cls = 'D:\\Users\\b\\IdeaProjects\\Automation\\src\\com\\mycomp\\tmo\\DBConnectionManager'

def map = ['person': ${cls}]
map['person'].newInstance()
DevOps Junky
  • 287
  • 1
  • 5
  • 22

1 Answers1

0

I think the post I asked two weeks ago can answer your question. Create resusable jenkins pipeline script

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Tim
  • 2,006
  • 2
  • 18
  • 25
  • Hi Tim, my repository is SVN, will the same work with SVN ? – DevOps Junky Aug 08 '16 at 11:05
  • Never try it, but I guess if you put your groovy code inside that work flow folder, it should be the same. – Tim Aug 08 '16 at 11:46
  • Hi Tim, the post you shared is one way of doing this, but it is not always feasible to access the library from git, as I said my repo is SVN. After discussing within my team, we understand that this way is not feaisble for us. Is there any other way I can load the file and call the methods ? – DevOps Junky Aug 08 '16 at 11:55
  • there is another answer in that post looks like this { // ...your pipeline code... git 'http://urlToYourGit/projectContainingYourScript' //Change this to svn clone pipeline = load 'global-functions.groovy' pipeline.helloworld() // Call one of your defined function // ...some other pipeline code... } – Tim Aug 08 '16 at 13:36