Set global environment variables inside the phase phase of the build Xcode script

I use Jenkins to create continuous integration. I have quite a few jobs that have large code of the same code. In the middle, I pulled all this into a shared script file, which I would like to run pre and post build.

I was unable to figure out how to set some environment variables inside this script so that both the Xcode build team and the Jenkins build can see them.

Does anyone know if this is possible?

+6
source share
2 answers

It is impossible to fulfill exactly what you ask. A process cannot change the environment variables of another process. Preliminary and post-actual assembly steps are performed in different processes.

But you can create a script that sets common environment variables and shares this script between all your assemblies.

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 might look like this:

 export VARIABLE1=value1 export VARIABLE2=value2 

How exactly your tasks will share the script depends on your environment and usage. You can

  • place the script in some famous place on the Jenkins host or
  • place the script in the version-controlled source code tree if all your jobs have a common repository or
  • place the script in your own repository and create a Jenkins assembly that archives the script as an assembly artifact. Then all other jobs will use the Copy Artifact plugin to get a copy of the script from the script job artifacts.
+5
source

From Apple Technical Q & A QA1067, it seems that if you create the file /Users/YOU/.MacOSX/environment.plist and fill it with the necessary environment variables, then all processes (started by the user with the environment.plist file in their home directory) will display these environment variables. You may need to restart your computer (or just log off and back out) before the new process picks up the variables.
This article also claims that Xcode will also pass these variables to the build phase of the script. I have not tested it yet, but the next time I restart my MacBook, I will let you know if it works.

From http://developer.apple.com/library/mac/#/legacy/mac/library/qa/qa1067/_index.html

Q: How do I set environment for all processes launched by a specific user?


A: It is actually a fairly simple process to set environment variables for processes launched by a specific user.

There is a special environment file in which loginwindow searches every time a user logs in. Environment file: ~ / .MacOSX / environment.plist (be careful case sensitive). where '~' is the home directory of the user we are interested in. you need to create the .MacOSX directory yourself using the terminal (by entering mkdir.MacOSX). You will also have to create an environment write yourself. The environment file is actually in XML / plist format (be sure to add the .plist extension to the end of the file name or this will not work).

0
source

Source: https://habr.com/ru/post/912618/


All Articles