首页 > 其他 > 详细

Jenkins Extended choice parameter之Groovy Script使用

时间:2020-07-22 12:02:05      阅读:525      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!