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