據我所能確定沒有任何單一方法調用將從Job中刪除用戶/權限。我寫了以下方法,因爲我有數百個作業,刪除舊用戶非常耗時。我在一些測試工作中成功使用了以下內容。我已將Extended Choice參數插件合併爲選擇用戶,並將此Groovy腳本作爲「源代碼值」
import hudson.security.*
import jenkins.security.*
import jenkins.model.Jenkins
def sids = Jenkins.instance.authorizationStrategy.getAllSIDs()
return sids
在構建部分;
def removeAMP(Job jobName, user) {
println jobName.name.center(80,'-')
def authorizationMatrixProperty = jobName.getProperty(AuthorizationMatrixProperty.class)
Map<Permission,Set<String>> Permissions = authorizationMatrixProperty.getGrantedPermissions()
println "Permission Map Before: " + Permissions + cr
println "Permission Values: " + Permissions.values() + cr
for (Set<String> permissionUsers:Permissions.values()) {
permissionUsers.remove(user)
}
println "Permission Map After: " + Permissions + cr
jobName.save();
}
testJobList = [ "TESTJOBA", "TESTJOBB" ]
testJobList.each {
jobName = hudson.model.Hudson.instance.getItem(it);
removeAMP(jobName, user)
輸出:
------------------------------------TESTJOBA------------------------------------
Permission Map Before: [Permission[interface hudson.model.Item,Read]:[bob,fred], Permission[interface hudson.model.Item,ExtendedRead]:[bob,fred], Permission[interface hudson.model.Item,Discover]:[bob,fred], Permission[interface hudson.model.Item,Build]:[bob,fred], Permission[interface hudson.model.Item,Cancel]:[bob,fred], Permission[interface hudson.model.Item,Workspace]:[bob,fred]]
Permission Values: [[bob,fred], [bob,fred], [bob,fred], [bob,fred], [bob,fred], [bob,fred]]
Permission Map After: [Permission[interface hudson.model.Item,Read]:[bob], Permission[interface hudson.model.Item,ExtendedRead]:[bob], Permission[interface hudson.model.Item,Discover]:[bob], Permission[interface hudson.model.Item,Build]:[bob], Permission[interface hudson.model.Item,Cancel]:[bob], Permission[interface hudson.model.Item,Workspace]:[bob]]
皮特嗨,感謝您的更新,我能夠撤消工作水平的用戶訪問而不是從管理詹金斯 - >配置全球安全 - >授權 - >用戶 – Vijay