I recently came across that kind of line of code in Podfile
pod 'PodName', git => 'https://' + ENV['USER'] + ':' + ENV['PASS'] + 'url'
The thing is those two, ENV[‘USER’]& ENV[‘PASS’] are set at the top of Podfile which I don’t think should be in Podfile at all as per security measures (please correct me if I’m wrong). So I’ve tried to move them out from Podfile.
Two approaches I’ve tried:
- move them into Environment Variables in the schema
- create Configuration Settings File and put them there
However, this not works, or I do not know how to do this.
So, the question is, is this possible to use some external variables in the Podfile?
If so, how?
Side note:
Interesting is that if I will remove the variables from the top of the file and put them into the pod-git URL I am getting the following error "no implicit conversion of nil into String" as if both variables are not there at all.
2
Answers
UPD: I totally misread the question, my apologies. My answer is about Fastlane (so, Fastfile, Appfile, etc.). I’ll leave it here just in case.
THE INFO BELOW IS ABOUT FASTLANE, NOT COCOAPODS!
Yes, it is possible: https://docs.fastlane.tools/advanced/other/
You can put
.env
or.env.default
files in the same directory as yourFastfile
. You can configure the environment variables in those files and then use them in yourFastfile
,Appfile
, etc.:.env
Appfile
Fastfile
You can also have multiple environments:
.env.CustomEnvironment
,.env.AnotherEnvironment
, etc. You can then pass the environment to use to Fastlane using the--env
parameter:I’m not sure if the Podfile can read from the environment (@FreeNickname’s answer seems to refer to the Fastfile instead), but my approach to private pods has always been a bit different.
Instead of a username/password in the URL, we use a private repository that only certain accounts have access to. CocoaPods uses the credentials of the signed in user to fetch the contents of the repo.
Optionally, you can set up a private spec repository that defines what are the latest versions of your private pods.
When it comes to CI, you have to make sure that the CI runner also has the right credentials to access this repositories.