首页 > 解决方案 > jenkins bash 脚本 - 从查找命令结果中删除目录路径

问题描述

我需要在我的 dist 目录中搜索 jenkins 中缩小的 .js 和 .css 文件。

我有一个带有 find cmd 的 bash 脚本,如下所示:

for path in $(/usr/bin/find dist/renew-online -maxdepth 1 -name "*.js" -or -name "*.css" -type f); do
# URL of the JavaScript file on the web server
url=$linkTarget/$path
echo "url=$linkTarget/$path"

其中 linkTarget 是:http ://uat.xxxx.com/renew-online 。

我想将 dist/renew-online 形式的缩小文件附加到 linkTarget,例如:

http://uat.xxxx.com/renew-online/main-es2015.cf7da54187dc97781fff.js

但我不断得到:http ://uat.xxxx.com/renew-online/dist/renew-online/main-es2015.cf7da54187dc97781fff.js

我也尝试过 -maxdepth 0 但无法获得正确的网址 - 脚本新手!

希望你们中的一个可以帮助,谢谢你的时间

标签: bashjenkinsfind

解决方案


这可以通过仅使用“查找”命令来实现:

/usr/bin/find dist/renew-online -maxdepth 1 \( -name "*.js" -o -name "*.css" \) -type f -printf "$linkTarget/%f\n"

还建议在圆括号内隔离“或”语句。


推荐阅读