sathishc58
sathishc58

Reputation: 31

How to add string parameter to a freestyle jenkins job via groovy?

I am new to Groovy and trying to add a string parameter to a Jenkins job via Groovy (not using plugins)

I found similar set of examples for Workflow job and not for FreeStyleProject

https://www.programcreek.com/java-api-examples/index.php?api=hudson.model.FreeStyleProject

If anyone could help me it would be great

Upvotes: 0

Views: 1882

Answers (2)

LazerBanana
LazerBanana

Reputation: 7221

You can use String Parameter Definition

It accepts 3 parameters

new StringParameterDefinition(parameterName, defaultValue, description)

Also, be sure to import it!

import hudson.model.*

Upvotes: 0

sathishc58
sathishc58

Reputation: 31

After searching for days, the following solution worked

ParameterDefinition paramDef = new StringParameterDefinition("CUSTOM_BUILD_PARAM", "Test", "");
ParametersDefinitionProperty paramsDef = new ParametersDefinitionProperty(paramDef);

job.addProperty(paramsDef);

where 'job' is of type 'FreeStyleProject'

Upvotes: 2

Related Questions