我正在尝试将一个执行cURL命令的groovy脚本导入到我的Jenkins管道中。当在管道外(例如从shell )执行groovy脚本时,cURL命令可以正确执行,但是当在管道内执行时,我的管道可以正常执行,但是cURL命令似乎没有执行。
test.groovy:
class GroovyClass{
def executeCurl() {
//define curl command and execute
def proc = "curl fakecommand".execute()
// cURL uses error output stream for progress output.
Thread.start { System.err << proc.err }
// Wait until cURL process finished
proc.waitFor()
}
}
return new GroovyClass();
Jenkinsfile:
if (run) {
def groovyClass= load 'test.groovy'
groovyClass.executeCurl()
}
发布于 2018-07-28 03:53:08
在Jenkinsfile中,您只能使用实现可序列化接口的类的对象。
如果不是这样,有时你会得到一条错误消息,有时它是偶然工作的,有时似乎什么也没发生。
如果您想使用不可序列化类型的对象,则需要将其封装在一个用@NonCPS
注释的方法中。除此之外,在创建进程时,这意味着您需要禁用沙箱模式。
然而,这并不是您想要的。因为这将在flyweight执行器中的master上执行curl,而flyweight执行器不应该执行任何此类任务。
要在节点上执行流水线中的内容,必须使用bat
或sh
步骤。
请务必检查Jenkins Pipeline tutorial以及步骤参考和代码段生成器。文件访问的工作方式也不同。
当然,您也可以调用groovy二进制文件,使用bat
或sh
从管道中运行脚本
https://stackoverflow.com/questions/51560740
复制相似问题