Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possibility of adding environment variables on Podfile

Tags:

cocoapods

Is it possible to add environment variables on Podfiles without having to create a custom shell script to replace strings inside my Podfile?

Example:

platform :ios, '10.0'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://<USERNAME>@bitbucket.org/awesometeamname/ios-private-specs.git'
use_modular_headers!

target 'a-generic-app-name' do
  use_frameworks!

  pod 'MaybeFirebase'
  pod 'AnotherSDK'
  pod 'AlamofireOfCourse'
  pod 'WhoUsesRxSwiftAnyway'

end

The reasoning behind this is that we're using a private pod spec repository that we connect to via ssh, and a developer will have to always Push or manually ignore Pushing the username, is it possible to set this via command line?

My current solution right now is that I have a script that I call instead of calling pod install this script does the ff:

  • Replace the <USERNAME> string
  • Call pod install
like image 985
Zonily Jame Avatar asked Nov 11 '19 05:11

Zonily Jame


People also ask

Why do we add environment variables?

Environment variables help programs know what directory to install files in, where to store temporary files, and where to find user profile settings. They help shape the environment that the programs on your computer use to run.


1 Answers

Yes, it's possible. Remember that you can still use ruby syntax in your Podfile. Let's assume you keep the username in env var named REPO_USERNAME. Then your file would look like:

platform :ios, '10.0'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://' + ENV['REPO_USERNAME'] + '@bitbucket.org/awesometeamname/ios-private-specs.git'
use_modular_headers!

target 'a-generic-app-name' do
  use_frameworks!

  pod 'MaybeFirebase'
  pod 'AnotherSDK'
  pod 'AlamofireOfCourse'
  pod 'WhoUsesRxSwiftAnyway'

end

Usage

REPO_USERNAME=Zonily pod install

Bonus

IMO cleaner solution for your problem would be to use SSH access instead of HTTPS. Then, you can create shared SSH key for your team, or add teammates SSH public keys to the repository, so all of them will have the access. In such case, you'll use the following lines for sources:

source '[email protected]/CocoaPods/Specs.git'
source '[email protected]/awesometeamname/ios-private-specs.git'

If you believe this could work for you, just browse Bitbucket's docs to see how to use SSH keys with your repository.

Cheers!

like image 135
wkukielczak Avatar answered Oct 05 '22 06:10

wkukielczak