iOS脚本自动打包 版本号自增

方法一:  iOS脚本设置build 号自增常规方法

#版本号自增
agvtool next-version
#设定值版本号
agvtool new-version 123
 

方法二:自动增加版本号的脚本命令可能有时不管用,可以使用一下方法:

#!/usr/bin/env bash

#获取当前版本号
get_build_version=`xcodebuild -showBuildSettings  -target MXLive | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION = '`
old_build_version=$get_build_version
echo "old_build_version = $old_build_version"

#版本号增加
agvtool new-version $(($old_build_version+1))

#输出新版本号
#get_current_build_veresion=`xcodebuild -showBuildSettings  -target MXLive | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION = '`
#current_build_veresion=$get_current_build_veresion
#echo "current_build_veresion = $current_build_veresion"

exit 0
 

相关命令行的解释:

iOS自动打包时可能需要读取buildSetting,xcode命令行命令 展示所有buildSetting:

xcodebuild -showBuildSettings -target 项目target

xcode命令行命令 展示某项buildSetting:

#如果要拿的是版本号的话(MARKETING_VERSION)
OUTPUT= xcodebuild -showBuildSettings -target 项目target | grep MARKETING_VERSION
echo $OUTPUT
#输出 MARKETING_VERSION = 1.0.0
#build号是CURRENT_PROJECT_VERSION

需要将其转为字符串的话,需要在两边加上这个符号`  还可以利用trcut方法对结果字符串进行修剪:

#如果版本号只需要对应的版本号数字
echo `xcodebuild -showBuildSettings -target BiBi | grep MARKETING_VERSION | tr -d 'MARKETING_lsVERSION ='`
#tr -d表示删掉对应的字符串

#或者
echo `xcodebuild -showBuildSettings -target BiBi | grep MARKETING_VERSION | cut -d '=' -f 2`
#-d '=' 表示设定裁剪的分隔符,默认为TAB
#-f 2 表示在分割符分割的区块内,取第2块,如果是2改成1的话,得到的就是MARKETING_VERSION了

#输出 1.0.0

参考链接

1.终端读取iOS项目所有设置参数(版本号、应用名等) https://www.cnblogs.com/MrYU4/p/16853290.html

2.iOS自动打包脚本 https://www.cnblogs.com/duzhaoquan/p/17083676.html

 

posted @ 2023-02-01 16:56  不停奔跑的蜗牛  阅读(697)  评论(0编辑  收藏  举报