Inject passwords to the build as environment variables Inject passwords to the build as environment variables jenkins jenkins

Inject passwords to the build as environment variables


After running the seed job, all manual changes to a generated job will be lost. That's intended behavior of the Job DSL plugin.

To use passwords in a Job DSL generated job, use the Credentials plugin to store the password (or any secret) in Jenkins. Then use the Credentials Binding plugin to map the password to an environment variable in the job. Have a look at the Job DSL wiki for an example.


@daspilker , @JesseGlick, Thank you very much for your responses. It helped me to write my first configure block in Jenkins. Mentioning my actions so for others facing same problem might help.

Since we are using Job DSL 1.27, I am not able to use credentials-Binding directly. So created a configure block and injected required variables through my .groovy script.

Note: You need to take the converted value for 'credentialsId' from '*****/job/config.xml if you are getting "credentialsId did not found" error.

static def credentialsBinding = { String userNameVar, String passwordVar, String credId, wrapperContext ->    def nodeBuilder = new NodeBuilder()    wrapperContext.wrapperNodes << nodeBuilder.'org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper'(plugin: "credentials-binding@1.4") {        bindings {            'org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding' {                usernameVariable userNameVar                passwordVariable passwordVar                credentialsId credId            }        }    }}