从Jenkins中获取CFBundleVersion以将其用作变量,例如$ {APP_VERSION} [英] Getting CFBundleVersion from within Jenkins to use it as a variable, something like ${APP_VERSION}
问题描述
我想做的是能够为Jenkins构建的提交添加标签.现在,我用Jenkins内部版本号标记提交,但是我还想添加在该应用程序版本前面的Info.plist CFBundleVersion中.
What I'd like to do is to be able to add a tag to commits which Jenkins is building from. Right now I tag commits with the Jenkins build number but I want to also add in the app version as listed in the Info.plist CFBundleVersion in front of that.
我想知道的是,如何使用Jenkins或其他方式获取该值,并能够将其用作Jenkins中的参数/变量?
What I want to know is, how I can grab that value using Jenkins or otherwise and be able to use that as a parameter/variable within Jenkins?
我已经看到了使用plistbuddy设置此值的参考,所以我认为有一种方法可以使用它来获得相同的值.虽然我不知道该如何以及如何将其运用于我可以在詹金斯使用的地方.
I've seen references to using plistbuddy to set this value so I would assume there's a way to use that to get the same value. Though how and how to get that to where I can use it in Jenkins I don't know.
为进一步说明,我正在Jenkins中使用Git Publisher创建标签并以这种格式推送标签
For further clarification I am using Git Publisher in Jenkins to create a tag and push it with this format
jenkinsbuild- $ BUILD_NUMBER
jenkinsbuild-$BUILD_NUMBER
这会在git中的提交上生成一个标签,如下所示-jenkinsbuild-303
This results in a tag on the commit in git like this - jenkinsbuild-303
假设我的应用程序当前为3.5版,我想要的标签是读取的-jenkinsbuild-3.5-303
What I want, assuming my app is currently at version 3.5 is a tag that reads - jenkinsbuild-3.5-303
推荐答案
我设法从@agy链接的答案中整理出一个解决方案.这是我所做的:
I managed to piece together a solution from the answer which @agy linked to. Here's what I did:
-
在Jenkins配置的构建"部分中,我将以下两行添加到Xcode步骤之后的执行Shell"步骤 :
APP_VERSION=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "path to your plist")
echo APP_VERSION=$APP_VERSION > appversion.properties;
在那之后,我添加了一个注入环境变量"步骤(我认为这是EnvInject插件的一部分),在该步骤中,我向"属性文件路径"中添加了"appversion.properties" 字段.
完成此操作后, APP_VERSION 现在可以在后续的Shell命令步骤中用作环境变量.
After this is done, APP_VERSION is now available as an environment variable in subsequent shell command steps.
这篇关于从Jenkins中获取CFBundleVersion以将其用作变量,例如$ {APP_VERSION}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!