2017-05-03 88 views
0

groovy腳本從jenkins項目角色獨自刪除用戶?

import hudson.security.* 
 
    import jenkins.security.* 
 
    import jenkins.model.Jenkins 
 

 
    def sids = Jenkins.instance.authorizationStrategy.getAllSIDs() 
 
    return sids 
 

 
In the Build Section; 
 

 
    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(); 
 
    }

我在詹金斯創建工作與「執行系統grrovy腳本」不從詹金斯全球role.with去除項目角色的用戶以下腳本,但如下我得到錯誤:

ERROR: Build step failed with exception 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: 
Script1.groovy: 10: unable to resolve class Job 
@ line 10, column 19. 
     def removeAMP(Job jobName, user) { 
        ^

1 error 

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302) 
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:861) 
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:550) 
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:499) 
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:302) 
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281) 
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731) 
at groovy.lang.GroovyShell.parse(GroovyShell.java:743) 
at groovy.lang.GroovyShell.parse(GroovyShell.java:723) 
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:680) 
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:666) 
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:81) 
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) 
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782) 
at hudson.model.Build$BuildExecution.build(Build.java:205) 
at hudson.model.Build$BuildExecution.doRun(Build.java:162) 
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534) 
at hudson.model.Run.execute(Run.java:1738) 
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) 
at hudson.model.ResourceController.execute(ResourceController.java:98) 
at hudson.model.Executor.run(Executor.java:410) 

構建步驟「執行系統Groovy腳本」標記建立成品失敗 :未能

請幫我正確script.Than ?提前KS Ashif

回答

0

你需要添加

import hudson.model.Job 
+0

我需要添加「導入hudson.model.Job」或無需我說,並檢查了以下錯誤:錯誤:構建步驟與失敗異常 groovy.lang.MissingMethodException:沒有方法的簽名:com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy.getAllSIDs()適用於參數類型:()values:[] 可能的解決方案:getSIDs(java。 lang.String),getClass() – Ashif

+0

看起來像導入解決了第一個編譯錯誤。這第二個錯誤更復雜。您正在使用自定義身份驗證策略插件。你需要看這個代碼和任何文檔。你需要你公司的同事幫助你進一步發展。 – chim

+0

是啊,非常感謝Chim,如果你能解決這個問題,請幫助我解決這個問題。否則你有任何groovy腳本來完成這個任務嗎? – Ashif