pipeline 多个参数如何传入
1.准备一个json文件
{ "NAME" : "Lucy", "AGE" : "18", "PHONE_NUMBER" : "13912345678", "ADDRESS" : "Haidian Beijing", "EMAIL" : "lucy@demo.com", "GENDER" : "male", "IS_MARRY" : false }
/tmp/Anthony/test.json写入上面的内容,保存,这个路径下面会用到
2.修改job成参数化构建
3.groovy代码
import hudson.model.*; pipeline{ agent any stages{ stage("Hello Pipeline") { steps { script { println "Hello Pipeline!" println env.JOB_NAME println env.BUILD_NUMBER } } } stage("Init paramters in json") { steps { script { println "read josn input file" json_file = INPUT_JSON? INPUT_JSON.trim() : "" prop = readJSON file : json_file name = prop.NAME? prop.NAME.trim() : "" println "Name:" + name } } } } }
4.调试
如果提示报错,没有readJSON方法,说明你jenkins环境没有安装插件:Utility Steps, 去插件管理中搜索并安装这个。