[英]How to set Jenkins environment variable from script
I'm trying to setup a script to increment the build number of my Xcode project. 我正在尝试设置一个脚本来增加我的Xcode项目的内部版本号。 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. 我进行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插件,但我不知道如何将我的shell脚本中的var导入环境变量。
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
设置为我需要的值,但是如何将其分配给环境变量以便我以后可以在我的工作中访问它?
Add a build step to execute shell - in there determine APP_BUILD_NUMBER
and output to file, eg 添加构建步骤以执行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 variables and set there Properties File Path to $WORKSPACE/build.properties
然后添加构建步骤注入环境变量并在那里设置属性文件路径到$WORKSPACE/build.properties
after that $APP_BUILD_NUMBER
is accessible in all build steps after as environment variable; 之后,在作为环境变量之后的所有构建步骤中都可以访问$APP_BUILD_NUMBER
; eg in Xcode build step 例如在Xcode构建步骤中
These are also worth considering 这些也值得考虑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.