Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set global environment variables inside Xcode build phase run script

I'm using Jenkins to do continuous integration builds. I have quite a few jobs that have much of the same configuration code. I'm in the midst of pulling this all out into a common script file that I'd like to run pre and post build.

I've been unable to figure out how to set some environment variables within that script, so that both the Xcode build command, and the Jenkins build can see them.

Does anyone know if this is possible?

like image 549
Bryan Avatar asked Apr 06 '12 16:04

Bryan


People also ask

How do I run a custom shell script in Xcode?

1 Select xcodeproj file of you project -> Select Target -> Select Build Phases -> Click on plus button (upper left corner) -> Select New Run Script Phase. 2If you want to run a script while it is being installed on the device then please check a little checkbox just below the script box.

What is Xcodebuild?

xcodebuild builds one or more targets contained in an Xcode project, or builds a scheme contained in an Xcode workspace or Xcode project. Usage To build an Xcode project, run xcodebuild from the directory containing your project (i.e. the directory containing the projectname. xcodeproj package).

What is Built_products_dir?

BUILT_PRODUCTS_DIR. Description: Directory path. Identifies the directory under which all the product's files can be found. This directory contains either product files or symbolic links to them.


1 Answers

It is not possible to do exactly what you ask. A process cannot change the environment variables of another process. The pre and post and actual build steps run in different processes.

But you can create a script that sets the common environment variables and share that script between all your builds.

The would first call your shell to execute the commands in the script and then call xcodebuild:

# Note the dot in the beginning of the next line. It is not a typo.
. set_environment.sh
xcodebuild myawesomeapp.xcodeproj

The script could look like this:

export VARIABLE1=value1
export VARIABLE2=value2

How exactly your jobs will share the script depends on your environment and use case. You can

  • place the script in some well-known location on the Jenkins host or
  • place the script in the version controlled source tree if all your jobs share the same repository or
  • place the script in a repository of its own and make a Jenkins build which archives the script as a build artifact. All the other jobs would then use Copy Artifact plugin to get a copy of the script from the artifacts of script job.
like image 193
sti Avatar answered Sep 18 '22 13:09

sti