jenkinsjenkins-pluginsjenkins-job-dsl

Unable to set Jenkins plugin settings by Jenkins Job DSL


I'm trying to set the settings of a specific jenkins plugin (authorize-project-plugin) using the JobDSL description language. Unfortunatly neither on the plugin nor on the Job DSL side are developers left, who could support this setup.

As far as I understood a plugin doesn't need to be specially designed to be supported by Job DSL. But there are some rules the plugin must follow to make it work.

I have tried multiple different configuration options but none of these work. Usually it leads to an exception telling me, that Job DSL is not able to configure the plugin.

I have documented the selveral options I tried here https://issues.jenkins.io/browse/JENKINS-73533 - for example:

properties {
    authorizeProjectProperty {
        specificUsersAuthorizationStrategy{
            userid('admin')
        }
    }
}

I think the method I need to call is this: https://github.com/jenkinsci/authorize-project-plugin/blob/8009ed846919318894875972af9f79fb820d1fe1/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategy.java#L115C12-L115C46

Is there maybe someone who could tell me what to change in the plugin or how to configure it?


Solution

  • In general if you need to find the Job DSL syntax of a specific plugin you can navigate to https://your.jenkins.installation/plugin/job-dsl/api-viewer/index.html, which will give you the useful Job DSL Plugin interface in which you can search for the needed syntax.

    In your case the search for authorizeProjectProperty shows the following usage format:

    properties {
      // Run builds with specified authorization.
      authorizeProjectProperty {
    
         strategy {
    
            // Run a build as an anonymous user.
            anonymousAuthorizationStrategy()
    
            // Run a build as a specified user.
            specificUsersAuthorizationStrategy {
               
               // ID of the user to run builds as.
               userid(String value)
    
               useApitoken(boolean value)
    
               apitoken(String value)
    
               // Password of the user specified in User ID.
               password(String value)
    
               // "Run as Specific User" restricts the job configuration only to the specified user.
               dontRestrictJobConfiguration(boolean value)
            }
    
        // Run a build as the SYSTEM user.
        systemAuthorizationStrategy()
    
        // Run a build as a user who triggered it.
        triggeringUsersAuthorizationStrategy()
       }
    }
    

    So this is the format you need to use.
    In your specific example try the following:

    properties {
        authorizeProjectProperty {
            strategy {
               specificUsersAuthorizationStrategy{
                  userid('admin')
               }
            }
        }
    }