如何通过脚本设置Jenkins环境变量 [英] How to set Jenkins environment variable from script

查看:502
本文介绍了如何通过脚本设置Jenkins环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个脚本来增加Xcode项目的内部版本号.我进行了API调用以获取当前的内部版本号,然后我希望对其进行递增,然后将该新的版本号用作环境变量,以便Xcode插件可以使用它.

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.

我安装了EnvInject插件,但是我不知道如何将var从我的shell脚本中获取到环境变量中.

I have the EnvInject plugin installed but I don't know how to get the var from my shell script into a Environment Variable.

APP_BUILD_NUMBER=$(curl --request GET 'https://api.domain.com/api/GetBuildNumber')
APP_BUILD_NUMBER=$((APP_BUILD_NUMBER +1))

这会将APP_BUILD_NUMBER设置为所需的值,但是如何将其分配给环境变量,以便以后在工作中可以访问它?

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?

推荐答案

添加构建步骤以执行shell-在此确定APP_BUILD_NUMBER并输出到文件,例如

Add a build step to execute shell - in there determine APP_BUILD_NUMBER and output to file, e.g.

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

然后添加构建步骤注入环境变量,并将属性文件路径设置为$WORKSPACE/build.properties

then add build step Inject environment variables and set there Properties File Path to $WORKSPACE/build.properties

之后,$APP_BUILD_NUMBER作为环境变量可以在所有构建步骤中访问;例如在 Xcode 构建步骤

after that $APP_BUILD_NUMBER is accessible in all build steps after as environment variable; e.g. in Xcode build step

这篇关于如何通过脚本设置Jenkins环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆