Adding user into AzureAd Matrix AuthorizationStrategy via jenkins job

Hi Everyone, Trying to add user with permission. Using AzureAD auth strategy. So far used below -

 stage('Update Jenkins Security Matrix') {
            steps {
                script {
                    def userId = env.userObjectId
                    def permission = hudson.model.Hudson.Administer 
                    def azureStrategy = Jenkins.instance.getAuthorizationStrategy()
                    def permissionEntry = new org.jenkinsci.plugins.matrixauth.PermissionEntry(permission, userId) 
                    azureStrategy.add(permission, permissionEntry)
                        

                    Jenkins.instance.save()
                }
            }
        }

Getting error :

Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: dafbe164-8fec-45cc-85f3-253d8806485b **14:31:04** groovy.lang.MissingPropertyException: No such field found: field java.lang.Class Administer **14:31:04** at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.unclassifiedField(SandboxInterceptor.java:402) **14:31:04** at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:386) **14:31:04** at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:375)

There is no hudson.model.Hudson.Administer
Try something like this

def userId = env.userObjectId
def permission = jenkins.model.Jenkins.ADMINISTER
def azureStrategy = Jenkins.instance.getAuthorizationStrategy()
def type = com.microsoft.jenkins.azuread.AuthorizationType.USER
def permissionEntry = new com.microsoft.jenkins.azuread.PermissionEntry(type, userId) 
azureStrategy.add(permission, permissionEntry)

Thanks for letting me know. But there is not such class found

15:28:34  WorkflowScript: 64: unable to resolve class com.microsoft.jenkins.azuread.PermissionEntry 
15:28:34   @ line 64, column 23.
15:28:34     def permissionEntry = new com.microsoft.jenkins.azuread.PermissionEntry(type, userId) 
15:28:34                           ^
15:28:34  
15:28:34  1 error
15:28:34  
15:28:34  	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)

Used plugin version - Microsoft Entra ID (previously Azure AD)
Version457.vf85d61f83b_26

Ok you wrote you use azureAD so I assumed you use that plugin. Then go back to the original package

...
def type = org.jenkinsci.plugins.matrixauth.AuthorizationType.USER
def permissionEntry = new org.jenkinsci.plugins.matrixauth.PermissionEntry(type, userId)
...

Many thanks. It worked :slight_smile: