jenkins流水线学习(工具)

本文详细介绍了Jenkins中PipelineUtilitySteps插件和pipelinebasicsteps的使用,包括读写JSON、Properties、YAML文件,删除目录,工作目录切换,错误处理,邮件发送,以及基础的retry、sleep、timeout和环境变量操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

smartvxworks

创造不易,感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值