Jenkins特意为了更好使用pipeline,开发了一些工具类,方便我们更好地在step中处理各种需求。
一、Pipeline Utility Steps
Pipeline Utility Steps
这是个插件,需要在jenkins插件管理安装。参考来源:Jenkins高级篇之Pipeline方法篇-Pipeline Utility Steps-2-方法readJSON和writeJSON_pipeline readjson-CSDN博客
1、findFiles (需要在项目下要有log文件)
2、readJSON (方法有两种参数,分别是文件路径和字符串;示例是文件路径;datas = readJSON text : json_string)
3、writeJSON (file入参是文件路径,json可以是readJSON的结果,也可以是转换为json的字符串;示例是writeJSON的方式)
4、readProperties (读取properties文件,得到是一个map对象)
5、readYaml (读取yaml文件,得到是一个map对象;有2种参数,同上面的readJson; datas = readYaml text : yaml_string)
6、writeYaml (入参是readYaml的结果,也可以是一个map)
pipeline { agent any stages { stage('env') { steps { script { println env.JOB_NAME println env.BUILD_NUMBER println env.WORKSPACE } } } stage('Utility Steps method---findFiles') { steps { script { files = findFiles(glob: '**/*.log') println files[0].name } } } stage('Utility Steps method---readJSON') { steps { script { file_path_read = env.WORKSPACE + "/package.json" rd_json = readJSON file : file_path_read println rd_json println rd_json.name } } } stage('Utility Steps method---writeJSON') { steps { script { file_path_write = env.WORKSPACE + "/test_jenkins.json" input_json = env.WORKSPACE + "/package.json" input = readJSON file : input_json writeJSON file: file_path_write, json: input } } } stage('Utility Steps method---readProperties') { steps { script { properties_file = env.WORKSPACE + "/test_jenkins.properties" props = readProperties interpolate: true, file: properties_file println props } } } stage('Utility Steps method---readYaml') { ste