DSL Script - Inject passwords to the build as environment variables

399 views
Skip to first unread message

Angel Yanev

unread,
Nov 3, 2016, 7:21:48 AM11/3/16
to Jenkins Users
Dear All,

I am trying to create a DSL template job that will generate jobs with  'Inject passwords to the build as environment variables' option and a want to add a name and a value. Until now I have this :

....
wrappers {
          environmentVariables {
           
            injectPasswords {
                injectGlobalPasswords(false)
                jobPasswords{
               
                }
            }
          
            buildName = '${TODAY_DATE}''
           
            envs(BUILD_NAME: "${buildName}")
            }
            buildName('${ENV,var="BUILD_NAME"}')
        }
....

However, I dont know how to add a name and a value. The jobPasswords {} block does not work and I have tried various combinations to add a password but with no success. I cant find anything on the internet as well.

I appreciate your help!

Thanks you!

Angel Yanev

unread,
Nov 3, 2016, 12:32:32 PM11/3/16
to Jenkins Users
I got it to work like this :

....

configure {
      
            def gblpass = it / 'buildWrappers' /

            'EnvInjectPasswordWrapper' <<
              {
                     injectGlobalPasswords ('false')
                     maskPasswordParameters ('true')

                     passwordEntries() <<
                             {
                               'EnvInjectPasswordEntry'
                                       {
                                          name('name')
                                          value('pass')
                                        }
                             }
               }
        }

Victor Martinez

unread,
Nov 3, 2016, 3:30:18 PM11/3/16
to Jenkins Users
You can use the autogenerated dsl syntax if you are above 1.46

- https://github.com/jenkinsci/job-dsl-plugin/wiki/Automatically-Generated-DSL

You can simplify a bit the configure closure with a more descriptive DSL

Cheers

Reply all
Reply to author
Forward
0 new messages