I am trying to add an user as an admin in Jenkins using groovy. When i do so, it removes permissions for all the existing users. Any idea on how I can do this.
I tried this code
import jenkins.model.*
import hudson.security.*
def instance = Jenkins.getInstance()
def strategy = new GlobalMatrixAuthorizationStrategy()
strategy.add(Jenkins.ADMINISTER, “foo”)
instance.setAuthorizationStrategy(strategy)
instance.save()
I was expecting to add user foo as an admin in jenkins, instead what happened was all the existing users lost their permissions from jenkins and were denied access. They were displayed an error like “missing overall/read permissions” when trying to access jenkins
Thank you so much for your response. I tried this code
import jenkins.model.*
import hudson.security.*
def instance = Jenkins.getInstance()
def strategy = new GlobalMatrixAuthorizationStrategy()
strategy.add(Jenkins.ADMINISTER, “foo”)
instance.setAuthorizationStrategy(strategy)
instance.save()
I was expecting to add user foo as an admin in jenkins, instead what happened was all the existing users lost their permissions from jenkins and were denied access. They were displayed an error like “missing overall/read permissions” when trying to access jenkins
Your creating a new strategy, adding just the one user to it, then replacing the existing strategy.
essentially you want to get the existing one, then if its not the strategy you want (if you care), replace it, then add the users.