Skip to content

Commit

Permalink
Update documention (#317)
Browse files Browse the repository at this point in the history
FIx documentation how to create via init.groovy
  • Loading branch information
mawinter69 authored Jul 19, 2023
1 parent d7f94d9 commit 31d51ec
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,34 @@ Configuration management can be used via [Jenkins Script Console](https://www.je
[Groovy Hook Scripts](https://www.jenkins.io/doc/book/managing/groovy-hook-scripts/), following example is creating an admin role & user based on plugin 3.1.

```groovy
import jenkins.model.Jenkins
import hudson.security.PermissionGroup
import hudson.security.Permission
import com.michelin.cio.hudson.plugins.rolestrategy.AuthorizationType
import com.michelin.cio.hudson.plugins.rolestrategy.PermissionEntry
import com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy
import com.michelin.cio.hudson.plugins.rolestrategy.Role
import com.synopsys.arc.jenkins.plugins.rolestrategy.RoleType
import hudson.security.Permission
import jenkins.model.Jenkins
import org.jenkinsci.plugins.rolestrategy.permissions.PermissionHelper
Jenkins jenkins = Jenkins.get()
def rbas = new RoleBasedAuthorizationStrategy()
/* create admin role */
Set<Permission> permissions = new HashSet<>();
permissions.add(Jenkins.ADMINISTER)
Role adminRole = new Role("admin",permissions)
Role adminRole = new Role("admin", permissions)
/* assign admin role to user 'admin' */
adminRole.addPermissionEntry(new PermissionEntry(AuthorizationType.USER, 'admin'))
/* assign admin role to group 'administrators' */
adminRole.addPermissionEntry(new PermissionEntry(AuthorizationType.GROUP, 'administrators'))
/* assign admin role to admin user */
globalRoleMap = rbas.getRoleMaps()[RoleType.Global]
globalRoleMap = rbas.getRoleMap(RoleType.Global)
globalRoleMap.addRole(adminRole)
globalRoleMap.assignUserRole(adminRole, 'admin')
globalRoleMap.assignGroupRole(adminRole, 'administrators')
jenkins.setAuthorizationStrategy(rbas)
jenkins.save()
```
jenkins.save()```
## License
[MIT License](./LICENSE.md)
Expand Down

0 comments on commit 31d51ec

Please sign in to comment.