pipeline{ agent any stages{ stage("任务申请"){ steps{ wrap([$class: 'BuildUser']) { script { //获取当前登录用户账户、姓名、邮箱 Applier_id = "${BUILD_USER_ID}" } script{ println Applier_id def auths = Jenkins.instance.securityRealm.loadUserByUsername(Applier_id) .authorities.collect{a -> a.authority} //获取用户所属组 println auths } } } } } }
Active choices parameter根据用户所属不同组返回不同结果:
import hudson.model.User import jenkins.model.* //def userid = User.current().id def auths = Jenkins.instance.securityRealm.loadUserByUsername(User.current().id) .authorities.collect{it -> it.authority} if("IT_Group" in auths){ return [ '查询邮箱管理员:selected', '查询用户绑定的邮箱' ] }else { return [ '查询邮箱管理员:selected', ] }