将批处理变量传递给Jenkins中的作业

时间:2016-02-10 20:04:35

标签: windows batch-file jenkins continuous-integration

我在Jenkins工作,运行Windows批处理命令来检索DLL的版本号:

setlocal enableextensions DisableDelayedExpansion

set "file=c:\\example.dll"

for /f %%a in (
    'wmic DataFile where "Name='%file%'" get Version ^| find "." '
) do set "currentVersion=%%a"`

查看控制台输出,currentVersion确实设置正确。

但是,在调用此批处理命令后,我尝试使用此变量作为值触发另一个作业:

Version=%currentVersion%

这项工作虽然没有认识到这一点,但文字字符串%currentVersion%会被传递。

如何将批处理脚本中currentVersion的值传递给触发的作业?

1 个答案:

答案 0 :(得分:0)

正如评论中所提到的,在批处理脚本执行结束后,您在批处理脚本中设置的变量不会对其他构建步骤可见。

您应该将值写入文本文件,例如将APP_VERSION=1.2.3写入version.properties并使用EnvInject plugin然后读入该属性。

然后环境变量APP_VERSION可用于后续构建步骤,并可用于触发另一个作业。