Groovy Script调用python脚本返回值,两种方式:
方法一:
添加pp01参数:
1.编写Python脚本test.py,内容如下:
#!/usr/bin/env python3
#coding=utf-8
import sys
a="aabbcc1"
mm2="%s,%s,%s"%(a,333,"cccc")
print(mm2)
python3 test.py返回结果如下:
aabbcc1,333,cccc
2.编写Groovy脚本,内容如下:
def retobj2 = "/usr/local/python3/bin/python3 /data/script/py/test.py".execute().text.readLines()
retobj2.each{
println it
}
方法二:
添加pp03参数:
test4.py脚本内容如下:
#!/usr/bin/env python #coding=utf-8import json jd = {"name":"fulei.sssyang","age":"18"} #jj要求返回json格式 jj = json.dumps(jd) print(jj)
python3 test4.py结果返回如下:
{"name": "fulei.sssyang", "age": "18"}
Groovy脚本内容如下:
def respText = "/usr/local/python3/bin/python3 /data/script/py/test4.py".execute().text def slurper = new groovy.json.JsonSlurper() def branchs = slurper.parseText(respText) return branchs
Jenkins Extended choice parameter之Groovy Script使用
原文:https://www.cnblogs.com/dreamer-fish/p/13359633.html