简体   繁体   English

如何从脚本中设置Jenkins环境变量

[英]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构建步骤中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Python中设置Jenkins环境变量 - Set Jenkins environment variable in Python 如何为运行脚本设置自定义环境变量 - How to set custom environment variable for run script 从自定义环境变量设置Xcode项目版本 - Set Xcode project version from custom environment variable 如何在运行脚本Xcode 10中读取自定义环境变量? - How to read a custom environment variable in a run script, Xcode 10? 如何在我的应用程序中从Xcode获取环境变量 - How can I get an environment variable from Xcode in my app 如何在Xcode的运行脚本构建阶段中指定在环境变量中包含空格的文件夹路径,该空格将传递给cp? - How to specify a folderpath containing spaces in an environment variable that will be passed to cp in the run script build phase in Xcode? 如何在Cocoa或Xcode编程中使用mainmenu nib(xib)文件设置setenv(设置环境变量)? - How to setenv (set environment variable) using mainmenu nib (xib) file in Cocoa or Xcode programming? .xcconfig?如何设置环境变量 - .xcconfig? How to set environment variables 如何在fastlane中设置环境变量? - How to set environment variables in fastlane? 从 CMake 设置 Xcode 环境变量 - Setting Xcode Environment Variable from CMake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM