简体   繁体   中英

Set Jenkins environment variable in Python

I'm building a Jenkins setup to automate the our iOS (Xcode) builds.

The flow right now is as follows:

  1. Build is triggered remotely. Passing the app's name, bundle ID, provisioning profile URL (among other data).
  2. Jenkins fetches the latest codebase version from git.
  3. A Python script is run to edit the app's Info.plist file based on the data provided in the trigger. This Python script also installs the provisioning profile using this approach .
  4. Jenkins uses the Xcode Plugin to build the project.

The Xcode Plugin allows you to specify the provisioning profile UUID to use to build the app. The Python file in step 3 gets this UUID. So now what I need is to save that UUID so it's accessible in a normal text form for the Xcode Plugin to use.

I've used the EnvInject Plugin to create and set an environment variable, which works and is usable in the Xcode Plugin's. But I cannot set this environment variable from any script (Python or Shell) while the job is running, it can only be hard-set in the job's configuration page.

Hope someone can help. Thanks!

But I cannot set this environment variable from any script (Python or Shell) while the job is running,

Yes you can.

  • Your Python/Shell script needs to write a value, in format param=value to a predetermined path/to/file.props (with some back-and-forth, this path can be dynamic too).
  • Configure the EnvInject to read from that path/to/file.props
  • So:

    1. Python/Shell runs dynamically and writes to file.
    2. EnvInject reads the file and loads the environment variables, including $param
    3. Your $param is now available for the rest of the job/scripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM