-
Bug
-
Resolution: Unresolved
-
Major
-
Jenkins: 2.289.3
Job DSL Plugin: 1.77
Mask Password Plugin: 3.0
Hello,
I'm using a DSL pipeline to create all my Jenkins jobs, from the job DSL plugin. Till now, when a password as parameter was required, I was using nonStoredPasswordParam from the "Mask Passwords" plugin.
pipelineJob(path) {
displayName(job_name)
description(description)
parameters {
choiceParam(it.name, it.choices, it.description)
stringParam(it.name, default_value, it.description)
nonStoredPasswordParam(it.name, it.description)
}
...}
Currently, one of my customer requires to be able to reuse its previous password (Rebuild or Replay from stage), even if the pipeline is recreated between the first build and the rebuild (bug correction). The only solution I found was to use the legacy passwordParam feature.
Unfortunately, I found no way to used it (passwordParam) in a DSL script and get this error message: ERROR: (unknown source) No signature of method: javaposse.jobdsl.dsl.helpers.BuildParametersContext.passwordParam() is applicable for argument types: (java.lang.String, null, java.lang.String) values: [APPOWNERPWD, null, Password demo]
Despite of this of error, I was able to create this kind of parameter using the direct declaration in the created pipeline or using a groovy:
- Create the password directly in the created pipeline itself: https://itnext.io/jenkins-tutorial-part-3-parameterized-pipeline-3898643ac6ad
pipeline
{ options
parameters
{ password(name: 'MY_PASSWD', defaultValue: 'default', description: 'My lovely password') }environment { ... }
agent { ... }
stages { ... }
}
- Modification of the pipeline once created using a Groovy script, like in https://medium.com/@mukeshsingal/update-default-values-of-jenkins-job-parameters-416de5ff9f96 :
path = "folder1/folder2/pipelineA"
name = "MY_PASSWD"
default_password = "default"
description = "My lovely password"
newParameters = []
newParam = new hudson.model.PasswordParameterDefinition(name, default_password, description)
newParameters.add(newParam)
Jenkins instance = Jenkins.getInstance()def job = Jenkins.instance.getItemByFullName(path)
for (prop in job.getAllProperties()) {if ( prop instanceof hudson.model.ParametersDefinitionProperty ) {
for (param in prop.parameterDefinitions) {
println("Taken Parameter: ${param.name}")
newParameters.add(param)
}
}
}
// Resetting the job pipeline definitionjob.removeProperty(ParametersDefinitionProperty.class)job.addProperty(new ParametersDefinitionProperty(newParameters))
instance.save()
Could you improve the DSL plugin to allow the usage of the hudson.model.PasswordParameterDefinition kind of parameter?
Regards