如何将Windows批处理变量作为构建参数导出到Jenkins中的以下步骤? [英] How to export windows batch variables as build parameters to following steps in Jenkins?
问题描述
在Jenkins中,是否可以将Windows批处理变量导出为构建参数?我知道在Windows批处理块中使用构建参数是,我经常使用它.
In Jenkins, is it possible to export windows batch variables as build parameters? I know using build parameters inside windows batch blocks is, I use it a lot.
例如,我有一个Windows批处理块,可以创建一个变量,例如A,
For example, I have a windows batch block that creates a variable, say A, like
SET A="MyVar"
是否可以在运行MSBuild时使用它,以/p:AssemblyName=%A%
或/p:AssemblyName=${A}
的(有效)语法将其作为构建参数传递给它?
Is it possible to use it in running MSBuild, passing it like it was a build parameter, in the (working) syntax of /p:AssemblyName=%A%
or /p:AssemblyName=${A}
?
这些似乎都不起作用(我的变量始终为空).
Neither of these seem to work (my variable is always empty).
更新:@Tuffwer建议使用EnvInject插件.我一直在尝试,但是到目前为止没有成功.这是我创建的一个示例,用于说明我的原始意图:
Update: @Tuffwer suggested using the EnvInject plugin. I have been trying, but so far without success. Here's a sample I created to illustrate my original intent:
我想创建一个变量,该变量的内容将根据在构建参数之一中应用的条件来确定.然后,我想使用/p:[Key] = [Value]语法将该变量作为MsBuild命令行的参数(如果我没有记错的话,则需要Jenkins MsBuild插件).
I want to create a variable which contents will be determined based on a condition applied in one of the build parameters. Then, I want to use that variable as a parameter to the MsBuild command line, using the /p:[Key]=[Value] syntax (which requires the Jenkins MsBuild plugin, if I am not wrong).
我现在仍然无法使用EnvInject.我需要在进一步的构建步骤中引用Windows批处理变量的值.
I still can't get this to work, now using EnvInject. I need to reference the value of a windows batch variable inside a further build step.
更新II :我变成了环境脚本插件,为我完成了工作.
Update II: I turned into Environment Script Plugin, which did the job for me.
推荐答案
建议使用 EnvInject 尝试,但与此同时再次寻找其他解决方案.
Tuffwer suggested using the EnvInject plugin, I tried did not succeed attaining what I intended. I edited my post including my EnvInject attempt, but in the meantime went searching again for other solutions.
这次,我遇到了环境脚本插件 ,它为我完成了工作.
This time I came across the Environment Script Plugin, which did the job for me.
步骤:
- 标记
Generate environment variables from script
- 对于要导出"的每个变量,您需要发出
echo [varName]=[value]
语句.
- Mark
Generate environment variables from script
- For each variable you want to "export", you need to issue an
echo [varName]=[value]
statement.
仅此而已.
然后,我的构建将创建一个名为 TRUE .exe或 FALSE .exe的程序集,具体取决于构建参数MyBool
的值.
That's all.
My build then creates an assembly named either TRUE.exe or FALSE.exe, depending on the build parameter MyBool
value.
这篇关于如何将Windows批处理变量作为构建参数导出到Jenkins中的以下步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!