如何通过 groovy 将字符串参数添加到 freestyle jenkins 作业?

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

我是 Groovy 的新手,正在尝试通过 [=27= 添加 字符串参数 Jenkins 作业 ](不使用插件)

我为 Workflow 作业找到了一组类似的示例,但没有为 FreeStyleProject

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

如果有人能帮助我那就太好了

搜索了几天后,以下解决方案奏效了

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

job.addProperty(paramsDef);

其中 'job' 的类型为 'FreeStyleProject'

您可以使用String Parameter Definition

接受3个参数

new StringParameterDefinition(parameterName, defaultValue, description)

还有,一定要导入!

import hudson.model.*