shell脚本和jenkins

1 压缩/解压缩

zip压缩命令

  • 参考:
    https://blog.csdn.net/MssGuo/article/details/117324818

tar压缩

  • 参考:
    https://blog.csdn.net/MssGuo/article/details/117387213

zip -r

+ zip -r www prd-uniapp-V4.04.30.wgt
    zip warning: name not matched: prd-uniapp-V4.04.30.wgt

zip error: Nothing to do! (try: zip -r www . -i prd-uniapp-V4.04.30.wgt)
  • 原因:
zip -r www prd-uniapp-V4.04.30.wgt

这个后面两个参数写反了。应该是:

zip -r prd-uniapp-V4.04.30.wgt www
  • 参考:
    https://blog.csdn.net/zhangpeterx/article/details/96887365
    https://blog.csdn.net/wojuzi/article/details/107723575

2 shell

shell sed

  • 参考:
    https://blog.csdn.net/qq_21933797/article/details/118284700
    https://blog.csdn.net/jaryle/article/details/77921506

shell匹配到字符串再替换整行

  • 参考:
    https://blog.csdn.net/qq_42761569/article/details/108081465

shell删除文件中的指定行

  • 参考:
    https://blog.csdn.net/yujia_666/article/details/108785416
    https://wenku.baidu.com/view/744c55cc5df7ba0d4a7302768e9951e79a896953.html

shell sed: erro

sed: 1: "test.json": undefined label 'est.json'
  • 参考:
    http://t.zoukankan.com/meitian-p-5907562.html
sed: 1: "i/versioCode/\"versionN ...": command i expects \ followed by text
  • 参考:
    https://blog.csdn.net/sunzhengtaolz/article/details/90354860
    https://blog.csdn.net/lord_y/article/details/99949999

Mac上sed命令使用变量

  • 参考:
    https://www.cnblogs.com/shuiche/p/12702313.html

shell grep

  • 参考:
    https://www.linuxprobe.com/linux-grep-sed.html

shell awk

  • 参考:
    https://blog.csdn.net/wdz306ling/article/details/80383824
    https://blog.csdn.net/huangyimo/article/details/79952886

shell字符串

  • 参考:
    http://c.biancheng.net/view/821.html

说明:该网站是比较详细的shell命令的教程。(当然也包括其他语言,比如C/C++/JAVA/Python等)

shell字符串提取数字

  • 参考:
    https://blog.csdn.net/wangjie5540/article/details/38047093/

shell正则提取版本号

  • 参考:
    https://blog.csdn.net/neve_give_up_dan/article/details/113613377
    http://cn.voidcc.com/question/p-gpnjqwpf-bmr.html

shell判断文件是否存在

  • 参考:
    https://blog.csdn.net/willingtolove/article/details/119932856

shell没有执行/shell部分命令没有执行只是打印出来了

  • 原因:shell命令,如下有问题:
echo "上传安卓文件成功:"$VersionName"/"$ANDROID_FILE"

在echo后面的字符串拼接应该是不合规范,导致这条命令之后的都没发正常执行

  • 参考:
    https://blog.csdn.net/u010333084/article/details/121926980
    https://blog.csdn.net/sdlyjzh/article/details/43935599

shell判断字符串相等

  • 参考:
    https://blog.csdn.net/weixin_35408656/article/details/113682373

3 jenkins

jenkins问题:

/tmp/jenkins2311422376864515502.sh: 70: /tmp/jenkins2311422376864515502.sh: Syntax error: Unterminated quoted string
Build step 'Execute shell' marked build as failure
  • 参考:
    https://blog.csdn.net/hu15081398237/article/details/112241608

原因:缺少双引号。
处理:这里是有一个cd路径的命令,最后面不知道怎么误写了一个双引号。去掉即可。

Jenkins Branches to build切分支

  • 参考:
    https://blog.csdn.net/weixin_38750084/article/details/108201514

  • 处理:Jenkins配置中在源码管理下的Branches to build修改内容为传入的参数,比如前面定义的tag这个参数,输入$tag即可。

Jenkins打包APP版本失败。

cd /opt/application/jenkins/jenkins_home/workspace/app-demo-uniapp-android
+ sed -i s/0.1.10/3.12.21/g /opt/application/jenkins/jenkins_home/workspace/app-demo-uniapp-android/app/src/main/assets/apps/__UNI__921542C/www/manifest.json
sed: can't read /opt/application/jenkins/jenkins_home/workspace/app-demo-uniapp-android/app/src/main/assets/apps/__UNI__921542C/www/manifest.json: No such file or directory
Build step 'Execute shell' marked build as failure
  • 原因:由于这是新版本。HBuilderX 3.2.16的离线版本已经修改了manifest对应的结构。原先的manifest是保留在离线项目中的,但是最新版本是合并在离线资源里的。
    导致原先需要对manifest进行配置更新的操作,最新版本不需要这么操作了。

  • 处理:去掉旧版本中针对manifest更新版本名称和版本号的操作(两条set -id脚本语句)。

Jenkins压缩文件报错:

unzip www.zip
Archive:  www.zip
replace www/__uniappes6.js? [y]es, [n]o, [A]ll, [N]one, [r]ename:  NULL
(EOF or read error, treating as "[N]one" ...)
Build step 'Execute shell' marked build as failure
  • 处理:
    查询了 UNZIP命令,通过-o 解决了这个问题 ,-o 使解压时不必先询问用户,unzip执行后覆盖原有文件。

  • 参考:
    https://www.cnblogs.com/liuyongcn/p/5433133.html

你可能感兴趣的:(shell脚本和jenkins)