【发布时间】:2018-01-03 16:42:48
【问题描述】:
我正在尝试更改我的文件的名称,在我的文件中添加提交次数和当前分支名称,然后再将其发送到存储库。
但我收到以下错误:
./publish_to_artifactory.sh:第 4 行:本地:`rev-parse': not a valid identifier'`
upload() {
local currentBranch=git rev-parse --abbrev-ref HEAD;
local gitNumberOfCommits=git rev-list --count HEAD;
for file in ./../*.ipa; do
mv $file mobile-${currentBranch}-${gitNumberOfCommits};
echo "uploading zeos-mobile-$currentBranch-$gitNumberOfCommits";
curl -X PUT -u $PUBLISH_USER:$PUBLISH_PASS -T mobile-$currentBranch-$gitNumberOfCommits; http://example.com/artifactory/ios-dev-local/ --fail
done
}
upload;
我做错了什么?
【问题讨论】:
-
顺便说一句,您根本不应该将命令替换与
local放在同一行——这样做会用local命令的退出状态隐藏这些替换的退出状态。 -
改为将
local currentBranch gitNumberOfCommits作为一行运行,然后将currentBranch=$(...)和gitNumberOfCommits=$(...)分别放在单独的一行。见Why doeslocalsweep the return code of a command? -
考虑通过shellcheck.net 运行您的代码,并修复它识别的各种引用错误。
-
非常有趣。谢谢!