zoukankan      html  css  js  c++  java
  • Jenkins之前置替换脚本内容

    在执行Jenkins任务前,需要修改执行的工程的某个文件中的内容,在前置步骤中编写脚本进行修改。

    Pre Steps Windows batch script

    @echo off
    
    CHCP 65001
    
    setlocal enabledelayedexpansion
    
    set file=src/test/java/org/weshare/sx/test/SXTest.java
    
    set "file=%file:"=%"
    
    for %%i in ("%file%") do set file=%%~fi
    
    set replaced=src/test/resources/授信脚本
    
    set all=src/test/resources/授信脚本/QmlxrTest
    
    for /f "delims=" %%i in ('type "%file%"') do (
    
       set str=%%i
    
       set "str=!str:%replaced%=%all%!"
    
       echo !str!>>"%file%"_tmp.txt
    
    )
    
    copy "%file%" "%file%"_bak.txt >nul 2>nul
    
    move "%file%"_tmp.txt "%file%"
    
    start "" "%file%"

    Pre Steps Linux shell  script

    cd src/test/java/org/weshare/bd/test
    sed 's/接口测试/接口测试/frogfish/g' BigDataTest.java > temp.java
    mv temp.java BigDataTest.java
    cat BigDataTest.java

    截图:

     参数化脚本:

    cd src/test/java/org/weshare/bd/test
    var1="接口测试/frogfish/四要素认证接口"
    sed 's/接口测试/'$var1'/g' BigDataTest.java > temp.java
    mv temp.java BigDataTest.java
    cat BigDataTest.java

    去除部分字段:

    cd src/test/java/sdd/ind/test/
    var1=""src/test/resources/中台接口/""
    var2=""
    sed 's/'$var1'/'$var2'/g' CucumberSampleTest.java > temp.java
    mv temp.java CucumberSampleTest.java
    cat CucumberSampleTest.java
  • 相关阅读:
    PowerMock详解
    java -agent与Javassist
    gradle_____最后到齐的构建工具
    JVM--参数调优
    提高速度 history 的利用
    shell-异步执行
    redis常用命令与使用分析
    chrome mac 快捷键
    idea的快捷键和操作
    mysql事务以及隔离级别
  • 原文地址:https://www.cnblogs.com/gongxr/p/8650099.html
Copyright © 2011-2022 走看看