我有一个需要参数的abc.groovy脚本。在我的地方我将它运行为通过运行在远程Linux机器上的jenkinsfile运行groovy脚本
$ groovy abc.groovy <argumentValue>
我已经下路"/home/path/to a directory/"
存储在此abc.groovy在远程Linux机器,我有一个Jenkinsfile一个詹金斯流水线作业。我如何从JenkinsFile调用abc.groovy。
我有一个需要参数的abc.groovy脚本。在我的地方我将它运行为通过运行在远程Linux机器上的jenkinsfile运行groovy脚本
$ groovy abc.groovy <argumentValue>
我已经下路"/home/path/to a directory/"
存储在此abc.groovy在远程Linux机器,我有一个Jenkinsfile一个詹金斯流水线作业。我如何从JenkinsFile调用abc.groovy。
您可以使用GroovyShell来评估您的脚本。
GroovyShell shell = new GroovyShell() def execute = shell.parse(new File('/path/to/abc.groovy')) execute.method()
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'
}
}
}
(本例中使用的声明管道语法,但很容易移植到脚本)
注意:你不能传递参数在Groovy脚本load
步骤,however this isn't hard to work around.