0

I have a abc.groovy script which takes an argument. In my local I run it as

$ groovy abc.groovy <argumentValue>

I have stored this abc.groovy in a remote linux box under path "/home/path/to a directory/" and I have a jenkins pipeline job with a Jenkinsfile. How can I call abc.groovy from the JenkinsFile.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
learner
  • 475
  • 3
  • 9
  • 23

2 Answers2

0

You can use GroovyShell to evaluate your script.

GroovyShell shell = new GroovyShell() def execute = shell.parse(new File('/path/to/abc.groovy')) execute.method()

ANIL
  • 2,542
  • 4
  • 25
  • 44
0

You'll want to use the load step in your Jenkinsfile like this:

def pipeline {
    agent 'slave'
    stages {
        stage ('Load Groovy Script') {
          steps {
              load 'path/to/abc.groovy'
          }
     }
}

(This example uses the declarative pipeline syntax, but is easily ported to scripted)

Note: you can't pass parameters to the groovy script in the load step, however this isn't hard to work around.

teakvinyl
  • 281
  • 1
  • 3