在执行Jenkins任务前,需要修改执行的工程的某个文件中的内容,在前置步骤中编写脚本进行修改。
Pre Steps Windows batch script
@echo offCHCP 65001setlocal enabledelayedexpansionset file=src/test/java/org/weshare/sx/test/SXTest.javaset "file=%file:"=%"for %%i in ("%file%") do set file=%%~fiset replaced=src/test/resources/授信脚本set all=src/test/resources/授信脚本/QmlxrTestfor /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>nulmove "%file%"_tmp.txt "%file%"start "" "%file%"
Pre Steps Linux shell script
cd src/test/java/org/weshare/bd/testsed 's/接口测试/接口测试\/frogfish/g' BigDataTest.java > temp.javamv temp.java BigDataTest.javacat BigDataTest.java
截图:
参数化脚本:
cd src/test/java/org/weshare/bd/testvar1="接口测试\/frogfish\/四要素认证接口"sed 's/接口测试/'$var1'/g' BigDataTest.java > temp.javamv temp.java BigDataTest.javacat BigDataTest.java
去除部分字段:
cd src/test/java/sdd/ind/test/var1="\"src\/test\/resources\/中台接口\/\""var2=""sed 's/'$var1'/'$var2'/g' CucumberSampleTest.java > temp.javamv temp.java CucumberSampleTest.javacat CucumberSampleTest.java