需求:
在jenkins的windows bat批处理脚本中,请求一个api返回json数据,然后获取返回值的某个指定key的value
直接上脚本:
cd C:\workspace\jenkinxx\workspace\job-ta-web git checkout master git pull dir :: 使用 curl 请求 API curl -s http://xx.xx.xx.xx:8088/testapi/getData > response.txt ::返回值类型格式:{"id": "19934889210", "title": "This is title", "access_url": "https://xx"}
:: 读取api返回的数据 ,获取到"19934889210"
for /f "tokens=2 delims=:," %%i in (response.txt) do (
set id_data=%%i
echo %id_data%
)
:: 读取id返回的数据并处理:去掉引号,获取到 19934889210
for /f "tokens=1 delims=" %%j in (%id_data%) do (
set id_value=%%j
echo %id_value%
)
echo %id_value%
:: 清理临时文件
del response.txt
::设置release_id的环境变量
set release_id=%id_value%
#python3 run_case.py "{\"testCasePath\":\"test.py::Testdata_test::test_sendMsgData\",\"release_id\":\"19934889210\"}"
python -m pytest -s .\testFolder\test.py::Testdata_test::test_sendMsgData --reruns 3 --reruns-delay 2
具体的,关于windows bat的读取文件的用法,可以参考: https://www.cnblogs.com/pingguomang/p/18570306
标签:bat,%%,Jenkin,xx,json,api,test,id From: https://www.cnblogs.com/pingguomang/p/18570349