如何将 Hudson/Jenkins 参数传递给 Windows 批处理命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18473652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:49:38  来源:igfitidea点击:

How can pass Hudson/Jenkins parameters to windows batch command

windowsbatch-fileparametersjenkinshudson

提问by davdomin

well i need to execute a batch file in my Hudson Job, I have a parameter(Jenkis parameter) and i need to pass this value like param to batch file, i tried this:

好吧,我需要在我的 Hudson Job 中执行一个批处理文件,我有一个参数(Jenkis 参数),我需要将此值(如 param)传递给批处理文件,我试过这个:

Deploy.cmd -configuration=${DEPLOYCONFIGURATION} -source=${DeploySource}

My Deploy.cmd is configurated for get this values but Jenkis doesn't assign the values.. For example, i have this:

我的 Deploy.cmd 被配置为获取这个值,但 Jenkis 没有分配值.. 例如,我有这个:

${DEPLOYCONFIGURATION} = DEV
${DeploySource} = c:\myFolder

Then,the batch file take this values

然后,批处理文件采用此值

%DEPLOYCONFIGURATION% = ${DEPLOYCONFIGURATION} 
%DeploySource% = ${DeploySource}

Takes the parameter name not its value

采用参数名称而不是其值

回答by Johnny Chen

Use %DEPLOYCONFIGURATION%instead of ${DEPLOYCONFIGURATION}in windows batch command

在 windows 批处理命令中使用%DEPLOYCONFIGURATION%代替${DEPLOYCONFIGURATION}

回答by Madhan

Execute your Batch file as like the below

执行您的批处理文件,如下所示

Deploy.cmd -configuration=%DEPLOYCONFIGURATION% -source=%DeploySource%

In case your Jenkins server run in unix/ Linux machine use "export" command to set environment variable for windows use "set" command like the below

如果您的 Jenkins 服务器在 unix/Linux 机器上运行,请使用“export”命令为 Windows 设置环境变量,请使用“set”命令,如下所示

For Windows:

对于 Windows:

set DEPLOYCONFIGURATION=DEV
set DeploySource=c:\myFolder

For Unix:

对于 Unix:

export DEPLOYCONFIGURATION = DEV
export DeploySource=c:\myFolder 

Hope it might solve your issue.

希望它可以解决您的问题。

Thanks, Madhan

谢谢,马丹