# How to provide an user overall admin access using groovy script?

**URL:** https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367
**Category:** Using Jenkins
**Created:** [May 10, 2022, 5:46am UTC](https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367 "2022-05-10T05:46:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![somali](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@somali](https://community.jenkins.io/u/somali)
#### Post date: [May 10, 2022, 5:46am UTC](https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367/1 "2022-05-10T05:46:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)
#### Post date: [May 10, 2022, 6:07am UTC](https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367/2 "2022-05-10T06:07:22Z")

</div>

Hi there,

“it doesn’t work” is always hard to remote debug. Try to always include these 3 things.

1. what did you try? (Code samples, command lines, screenshots, videos, etc)
2. what did happen? (Error messages, description, outputs, stuff)
3. what did you expect to happen?

Otherwise, it’s hard for us to get into your context and you’ll have to have someone who is exactly knowledgeable come along.

---

<div class="post-metadata">

### Author: ![somali](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@somali](https://community.jenkins.io/u/somali)
#### Post date: [May 10, 2022, 6:10am UTC](https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367/3 "2022-05-10T06:10:56Z")

</div>

Hi Gavin,

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

---

<div class="post-metadata">

### Author: ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)
#### Post date: [May 10, 2022, 6:25am UTC](https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367/4 "2022-05-10T06:25:24Z")

</div>

> [@somali](#):
>
> def strategy = new GlobalMatrixAuthorizationStrategy()  
> strategy.add(Jenkins.ADMINISTER, “foo”)  
> instance.setAuthorizationStrategy(strategy)

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.

---

<div class="post-metadata">

### Author: ![somali](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@somali](https://community.jenkins.io/u/somali)
#### Post date: [May 10, 2022, 6:57am UTC](https://community.jenkins.io/t/how-to-provide-an-user-overall-admin-access-using-groovy-script/2367/6 "2022-05-10T06:57:19Z")

</div>

Problem got solved. Thanks a lot Gavin
