使用bat文件在Jenkins中设置环境变量吗? [英] Setting environment variables in Jenkins with a bat file?

查看:105
本文介绍了使用bat文件在Jenkins中设置环境变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个批处理文件,用于设置开始构建过程之前所需的所有环境变量.

Currently I have a batch file that sets all the environment variables needed before starting the build process.

必须使用相同的bat来设置env变量.

It's a must to use the same bat for setting the env variables.

我尝试使用EnvInject插件,但没有成功.

I tried to use EnvInject Plugin, didn't have any success.

在运行msbuild之前,还尝试了执行Windows批处理命令".例如启动mybat.bat-这似乎也不起作用

Also tried "Execute Windows batch command" before running msbuild. e.g. start mybat.bat - this didn't seem to work either

如何集成相同的bat文件来设置变量?

How can I integrate the same bat file to set the variables?

推荐答案

每个Jenkins构建步骤"都有其自己的环境,我在此答案中对此进行了详细说明:

Each Jenkins "build step" has it's own environment, I explained this in detail in this answer: Can not change Jenkins String Parameter Variable

如果您使用的是MSBuild插件,那是它自己的构建步骤,因此使用其他构建步骤来更改环境是徒劳的.如果要使用执行Windows批处理命令"通过命令行启动MSBuild,则只需在同一个构建步骤中运行bat文件,然后再执行MSBuild命令

If you are using the MSBuild plugin, it is its own build step, so using other build steps to change the environment is futile. If you are launching MSBuild through command line using "Execute Windows batch command", then just ran your bat file within the same build step, preceding the MSBuild command

对于MSBuild插件,唯一正确的方法是使用EnvInject插件.也许您应该尝试找出EnvInject插件对您不起作用的地方.从示例文档中,您要使用"在作业级别"配置中,以.bat文件中的变量填充整个作业.

In the case of MSBuild plugin, the only proper way is to use EnvInject plugin. Maybe you should try to figure out what isn't working for you with EnvInject plugin. From the example documentation, you want to be using "At job level" configuration, to populate your whole job with the variables from your .bat file.

这篇关于使用bat文件在Jenkins中设置环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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