Kyle
Kyle

Reputation: 14666

Passing a Build Number to xcargs in Fastlane/Gym

I have an app with some app extensions. In order to keep the app extensions and the main app using the same version and build number, I have configured a user defined variable such as "MY_BUILD_NUMBER" and "MY_VERSION". In my app and my extensions Info.plist file, I just load those variables via ${MY_BUILD_NUMBER} and ${MY_VERSION}.

This process works great for keeping my versions and builds in sync. I'm now trying to research to see if I can pass the build number from Jenkins into fastlane via gym and update my xcargs. However, I've been failing to make this work appropriately with the quotes needed.

The examples show that I need to set it like so:

gym(xcargs: "my_build_number='123'")

But when I try to pass this in as an option, I can pass in the build number of "123". But I'm struggling at how to interpolate into the string that I need in xcargs "my_build_number='123'".

Has anyone successfully done something like this that could provide some insight? Do I need to escape the quotes somehow?

Upvotes: 0

Views: 6370

Answers (2)

trishcode
trishcode

Reputation: 3549

I am able to pass a variable as an xcarg using this syntax:

variable -> @build_number

xcargs: "BUILD_VERSION='#{@build_number}'"

~OR~

variable -> ENV["BUILD_NUMBER"]

xcargs: "BUILD_VERSION='#{ENV["BUILD_NUMBER"]}'"

Full example:

@build_number = latest_testflight_build_number(app_identifier: @AppBundleID) + 1
increment_build_number(build_number: @build_number)
build_app(scheme: "Release", export_method: "app-store", xcargs: "BUILD_VERSION='#{@build_number}'")

Upvotes: 5

Lyndsey Ferguson
Lyndsey Ferguson

Reputation: 5374

We set the bundle version for the app and the extensions at the same time in fastlane before gym:

set_info_plist_value(
  key: 'CFBundleVersion',
  value: build_number,
  path: info_plist_file
)

version_string = get_info_plist_value(
  key: 'CFBundleShortVersionString',
  path: info_plist_file
)

update_info_plist(
  xcodeproj: project_filepath,
  plist_path: notification_service_info_plist_relpath,
  block: lambda do |plist|
    plist['CFBundleVersion'] = build_number
    plist['CFBundleShortVersionString'] = version_string
  end
)

Upvotes: 6

Related Questions