Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can pass Hudson/Jenkins parameters to windows batch command

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:

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:

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

Then,the batch file take this values

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

Takes the parameter name not its value

like image 596
davdomin Avatar asked Aug 27 '13 19:08

davdomin


People also ask

How can we get a parameter value in parameterized job when running on Windows?

The parameter is available as environment parameters. So e.g. a shell ($FOO, %FOO%) or Ant ( ${env. FOO} ) can access these values. This is not exactly a return value, but you can pass any parameter (with its value) to the downstream job with Parameterized Trigger Plugin.

How do I run a batch script in Jenkins?

Add the batch command as run. Click on Apply and save the configuration then, you will redirect to the Project Workspace. Click on the Build Now, it will execute the given batch command that executes the run. bat file. You can see the console results on the Console Output.


2 Answers

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

like image 94
Johnny Chen Avatar answered Sep 19 '22 18:09

Johnny Chen


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

For Windows:

set DEPLOYCONFIGURATION=DEV
set DeploySource=c:\myFolder

For Unix:

export DEPLOYCONFIGURATION = DEV
export DeploySource=c:\myFolder 

Hope it might solve your issue.

Thanks, Madhan

like image 27
Madhan Avatar answered Sep 18 '22 18:09

Madhan