Gogi
Gogi

Reputation: 1695

Jenkins/Hudson job parameters at runtime?

PROBLEM

Let's say I have a jenkins/hudson job (for example free-style) that takes two parameters PARAM_ONE and PARAM_TWO. Now, I do not know the values of those parameters, but I can run some script (perl/shell) to find values of those parameters and then I want the user to select from a dropdown list after which I can start the build.

Is there any way of doing that?

Upvotes: 2

Views: 9838

Answers (3)

Michael Michael
Michael Michael

Reputation: 61

In Java, you can access these parameters off the run object

EnvVars envVars = new EnvVars();
envVars = run.getEnvironment(listener);
for (String envName2 : envVars.keySet()) {
   listener.getLogger().println(envName2 + " = " + envVars.get(envName2));
}

Upvotes: 0

LivCool
LivCool

Reputation: 253

Just install this, and give the parameter in the build script like:

Windows

"your build script" %PARAMONE% %PARAMTWO%

Upvotes: 0

Jack Leow
Jack Leow

Reputation: 22477

Sounds like you've found a plug-in that does what you need, that is pretty similar to the built-in Parameterized Builds functionality.

To answer your second question: when you define parameterized builds, the parameters are typically passed to your job as environment variables. So you'd access them however you access environment variables in your language, for instance, if you defined a parameter PARAM_ONE, you'd access it as:

In bash:

$PARAM_ONE

In Windows batch:

%PARAM_ONE%

In Python:

import os
os.getenv('PARAM_ONE')

etc.

I imagine this would be the same for the Extended Choice Parameter plugin you are using.

Upvotes: 3

Related Questions