How to create an "Item Role" and assign it to a Jenkins user using a groovy script

387 Views Asked by At

In Jenkins I use the plug-in "Role-based Authorization Strategy" to manage permissions.

I simply have two "Global Roles": user and "admin". admin can do anything, and user can simply view jobs a execute them.

But I would like to have a personal folder for each user where they can create jobs and configure them and basically do anything that don't affect the rest of the Jenkins platform.

To do so, I think the best option is to create "Item Roles" with the pattern of the personal folders of each user, and assign them to their corresponding users. But that is too much work, and not all users may need that personal folder.

Instead, I would prefer to have a job called "CreateMyFolder" that creates a folder named as the user that executed that job, create the "Item Role", and assign it to the user.

So far, I've managed to create the folder with:

import com.cloudbees.hudson.plugins.folder.*
import jenkins.model.Jenkins

def jenkins = Jenkins.getInstance()
def userName = jenkins.getMe().toString()
def parentFolderName = "DailyWork"
def parentFolder = jenkins.getItemByFullName(parentFolderName)
folder = parentFolder.createProject(Folder.class, userName)

Looks like "com.michelin.cio.hudson.plugins.rolestrategy" needs to be used, but I'm struggling to get it done.

Any idea about how to use that package?

Thank you a lot!

0

There are 0 best solutions below