LoginSignup
17
6

More than 3 years have passed since last update.

CIでXcode11の$(MARKETING_VERSION)からリリースバージョン番号を取得する

Last updated at Posted at 2019-11-15

前提

Xcode11からリリースバージョン番号を管理するInfo.plistの値 CFBundleShortVersionString が静的な値ではなく、Build Settingsの $(MARKETING_VERSION) を参照するようになっている。
(XcodeのGeneralタブから値を変更しても $(MARKETING_VERSION) が変更される)

image.png

問題点

CIで今までどおり、Info.plistから値を取得すると、 $(MARKETING_VERSION) という文字列で返ってきてしまう
例えばバージョン番号でタグ打ちするときなど参照するケースは結構あると思う。

対処法(shell script)

Build Settingsから取得する必要がある。
下記のワンライナーで取得できる(stack overflowの回答より:pray:)

version=$(sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' {プロジェクト名}.xcodeproj/project.pbxproj)

参考:
https://stackoverflow.com/questions/56722677/how-to-read-current-app-version-in-xcode-11-with-script/58769925#58769925

Bitriseで利用する場合

Scriptのステップを使って利用すると良さそう。
(下記にあるfastlaneのプラグインを使ってlaneを実行しても可)

例) リリースバージョン番号をGIT_TAGという環境変数にセット

#!/usr/bin/env bash
# fail if any commands fails
set -e

# get release number from Xcode build settings
version=$(sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' {プロジェクト名}.xcodeproj/project.pbxproj)

if [ -z "${version}" ]; then
  echo "[ERROR] failed to get MARKETING_VERSION"
  exit 1
fi

envman add --key GIT_TAG --value "${version}(${BITRISE_BUILD_NUMBER})"

対処法(fastlane)

versioningというfastlaneのプラグインではすでに対応が済んでいる

https://github.com/SiarheiFedartsou/fastlane-plugin-versioning/issues/37
https://github.com/SiarheiFedartsou/fastlane-plugin-versioning#about-versioning

17
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
6