简体   繁体   中英

pass groovy string variable into jenkins job dsl authorization

I have such job dsl configuration, but it does NOT update authorization (no errors, no changes):

def JobName = "myjob1"
def app_matrix_list = ['user1','user2']

app_matrix_list.find {          
        def ldap_id = it      
        auth_perm = auth_perm + "\npermission('hudson.model.Item.Build', '${ldap_id}')".stripIndent()     
}

job("${JobName}") {       
      authorization {"${auth_perm}"}
}

It creates myjob1 successfully , but authorization does not update. However println show auth_perm string value:

permission('hudson.model.Item.Build', 'user1')
permission('hudson.model.Item.Build', 'user2')

Please advise how to pass string variable to authorization section in job dsl?

I found solution and it works successfully:

job("${JobName}") {
.....    
        authorization {
            permission('hudson.model.Item.Read', 'anonymous')
            permission('hudson.model.Item.Read', 'authenticated')
            for (ldap_account in ldap_accounts_list) {
                permissions("$ldap_account",['hudson.model.Item.Build','hudson.model.Item.Cancel','hudson.model.Item.Read'])
            }
....                 
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM