从git到您的应用程序中最简单的方法来获取构建版本信息。
PXBuildVersion是一组用于生成有关您的应用程序的构建版本信息的脚本。这包括构建日期、版本控制信息(git提交SHA、分支和标签)以及构建时捕获的其他任何环境变量。
支持Jenkins CI、Travis CI和Circle CI构建号。
PXBuildVersion可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中:
pod 'PXBuildVersion'
您还需要添加一个构建脚本。最简单的方法是将一个post_install钩子添加到您的Podfile
中。如果您已经在Podfile
中有一个post_install部分,只需将内容添加到现有的post_install中,因为每个Podfile
只允许一个post_install钩子。
post_install do |installer|
if File.exists?('Pods/PXBuildVersion')
require_relative 'Pods/PXBuildVersion/scripts/util/setup.rb'
pxbuildversion_setup(installer)
end
end
一旦您的Podfile
配置正确,只需运行pod install
即可安装!
使用很简单!
NSLog(@"git sha: %@", [PXBuildVersion commit]);
if ([PXBuildVersion tag] != nil) {
NSLog(@"git tag: %@", [PXBuildVersion tag]);
}
if let commit = PXBuildVersion.commit() {
print("git sha: \(commit)")
}
if let tag = PXBuildVersion.tag() {
print("git tag: \(tag)")
}
将其添加到您的设置页面。或者,添加到您的崩溃报告工具,以帮助追踪问题!
[[Crashlytics sharedInstance] setObjectValue:[PXBuildVersion commit] forKey:@"commit"];
通过调整设置脚本,您可以控制版本负载中生成的环境变量。
-e, --env [NAMES] Comma separated list of env variable names
--all-env Dump all environment env variables found
--exclude-default Exclude default env variables
这些选项可以应用于Podfile
中的设置脚本。
将您的Podfile中的pxbuildversion_setup
行更新为指定确切的脚本,指定任何选项。
if File.exists?('Pods/PXBuildVersion')
require_relative 'Pods/PXBuildVersion/scripts/util/setup.rb'
pxbuildversion_setup(installer, script: %(\"${PODS_ROOT}/PXBuildVersion/scripts/git.rb\" -e NODE_NAME,BUILD_URL --exclude-default))
end
然后根据需要访问任何捕获的环境变量
if let buildNode = PXBuildVersion.environmentVariables()["NODE_NAME"],
buildUrl = PXBuildVersion.environmentVariables()["BUILD_URL"] {
print("This was built by Travis CI on node: \(buildNode)")
print("Access the build job details at: \(buildUrl)")
}
else {
print("Perhaps we should automate our builds with a CI server")
}
PXBuildVersion在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。