xcode 如何从脚本设置 Jenkins 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23785651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set Jenkins environment variable from script
提问by ChickensDontClap
I'm trying to setup a script to increment the build number of my Xcode project. I make an API call to get the current build number, then I wanted to increment it and apply that new number as an environment variable so that the Xcode Plugin can use it.
我正在尝试设置一个脚本来增加我的 Xcode 项目的内部版本号。我进行了一个 API 调用以获取当前的内部版本号,然后我想增加它并将该新号作为环境变量应用,以便 Xcode 插件可以使用它。
I have the EnvInject plugin installed but I don't know how to get the var from my shell script into a Environment Variable.
我安装了 EnvInject 插件,但我不知道如何将 var 从我的 shell 脚本获取到环境变量中。
APP_BUILD_NUMBER=$(curl --request GET 'https://api.domain.com/api/GetBuildNumber')
APP_BUILD_NUMBER=$((APP_BUILD_NUMBER +1))
This sets APP_BUILD_NUMBER
to the value I need, but how do I assign this to a environment variable so I can access it later on in my job?
这将设置APP_BUILD_NUMBER
为我需要的值,但如何将其分配给环境变量,以便稍后在我的工作中访问它?
回答by MrsTang
Add a build step to execute shell - in there determine APP_BUILD_NUMBER
and output to file, e.g.
添加一个构建步骤来执行 shell - 在那里确定APP_BUILD_NUMBER
并输出到文件,例如
APP_BUILD_NUMBER=$(curl --request GET 'https://api.domain.com/api/GetBuildNumber')
APP_BUILD_NUMBER=$((APP_BUILD_NUMBER +1))
echo APP_BUILD_NUMBER=$APP_BUILD_NUMBER > build.properties
then add build step Inject environment variablesand set there Properties File Pathto $WORKSPACE/build.properties
然后添加构建步骤 注入环境变量并将属性文件路径设置为$WORKSPACE/build.properties
after that $APP_BUILD_NUMBER
is accessible in all build steps after as environment variable; e.g. in Xcodebuild step
之后$APP_BUILD_NUMBER
在作为环境变量之后的所有构建步骤中都可以访问;例如在Xcode构建步骤中
回答by Federico
These are also worth considering
这些也值得考虑