Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change user-defined variable from fastlane

Tags:

xcode

fastlane

I have a user-defined variable in my Xcode project - MY_VARIABLE:
enter image description here I linked MY_VARIABLE also in my .plist file:
enter image description here And then I use it in my code:
NSString *myVariable = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MY_VARIABLE"];

In the fastfile I have my AppStore lane and, only in that case, I would like to change the value of MY_VARIABLE.

I'm currently using:
ENV["MY_VARIABLE"] = "appStoreValue"
but this doesn't work.

like image 247
tagyro Avatar asked Jul 12 '16 12:07

tagyro


People also ask

How do I view environment variables in Fastlane?

Fastfile and Co are just Ruby code, so you can use ENV['XYZ'] to access any environment variables.

What is Fastlane ENV?

fastlane also has a --env option that allows loading of environment specific dotenv files. . env and .env.default will be loaded before environment specific dotenv files are loaded. The naming convention for environment specific dotenv files is .env.<environment>


2 Answers

After a bit of research I found a solution to this.
I'm using xcargs in the gym action, like:

gym(
  scheme: "MyScheme",
  configuration: "Release",
  use_legacy_build_api: 1,
  xcargs: "MY_VARIABLE=appStoreValue"
)
like image 126
tagyro Avatar answered Oct 16 '22 07:10

tagyro


Thx to https://stackoverflow.com/a/56179405/5790492 and https://nshipster.com/xcconfig/
I've created the xcconfig file, added it to project in Info tab. For fastlane added this plugin to work with xcconfig. And now it looks like:

def bumpMinorVersionNumber
    currentVersion = get_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                                        name: 'FC_VERSION')
    versionArray = currentVersion.split(".").map(&:to_i)
    versionArray[2] = (versionArray[2] || 0) + 1
    newVersion = versionArray.join(".")
    update_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                          name: 'FC_VERSION',
                          value: newVersion.to_s)
    UI.important("Old version: #{currentVersion}. Version bumped to: #{newVersion}")
end

def bumpBuildNumber
    currentBuildNumber = get_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                                            name: 'FC_BUILD')
    newBuildNumber = currentBuildNumber.to_i + 1
    update_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                          name: 'FC_BUILD',
                          value: newBuildNumber.to_s)
    UI.important("Old build number: #{currentBuildNumber}. Build number bumped to: #{newBuildNumber}")
end

enter image description here

like image 1
Nik Kov Avatar answered Oct 16 '22 05:10

Nik Kov