Does anybody have an idea, if its possible, then how to read the permissions for given Jenkins folder?
- using CloudBees Folder plugin
- (https://wiki.jenkins.io/display/JENKINS/CloudBees+Folders+Plugin)
- using Matrix Authorization Strategy
- (https://plugins.jenkins.io/matrix-auth)
I found the way how to iterate over jobs and get Folder
"jobs"
But have no idea how to access the folder permisisons/read it
Access to folder is pretty simple
import com.cloudbees.hudson.plugins.folder.*
import groovyjarjarasm.asm.Item
def items=Jenkins.instance.getAllItems();
items.each{
if(it instanceof Folder){
println it.fullName
}
}
I noticed, when eg. on folder 'A' will grant to user Aread (ldapid) read permissions, then in config file is following
<com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>
<inheritanceStrategy class="org.jenkinsci.plugins.matrixauth.inheritance.InheritParentStrategy"/>
<permission>com.cloudbees.plugins.credentials.CredentialsProvider.View:Aread</permission>
I found also javadoc for cloudbee's folder class, but there is nothing about permision :/
Thanks for your tips (I am using inbuilt script editor for running groovy script)
After some findings I found some clues in Jenkins Add permissions to jobs using groovy
But, when implemented
import com.cloudbees.hudson.plugins.folder.*
import groovyjarjarasm.asm.Item
import jenkins.model.Jenkins
import hudson.security.*
import hudson.model.*
//AbstractProject proj = Hudson.instance.getItem("YourJob")
//AuthorizationMatrixProperty authProperty = proj.getProperty(AuthorizationMatrixProperty.class)
def items=Jenkins.instance.getAllItems();
items.each{
if(it instanceof Folder){
println it.fullName
AbstractProject proj = Hudson.instance.getItem(it.fullName)
AuthorizationMatrixProperty authProperty = proj.getProperty(AuthorizationMatrixProperty.class)
}
}
got an error
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.cloudbees.hudson.plugins.folder.Folder@a35435b[fooFolderName]' with class 'com.cloudbees.hudson.plugins.folder.Folder' to class 'hudson.model.AbstractProject'
(already tried it.name, / it as well :/ - code snippet will do not fail if there is not a folder, but classic job