Test
processed by David.fx
Subject: Re: Jenkins, update the project security via a groovy script not
working (26-Jun-2015 10:03)
From: [email protected]
To: [email protected]
Hi,
This is the way to update user access using groovy scrip:
import hudson.model.*
import jenkins.security.*
import hudson.security.*
// For each project
for(item in Hudson.instance.items) {
if(item.name.equalsIgnoreCase("AuthenticationChecker_SE"))
{
println(item.name)
println("Current USer "+User.current());
def authorizationMatrixProperty =
item.getProperty(AuthorizationMatrixProperty.class)
User user= User.current();
String sID= user.getId() ;
authorizationMatrixProperty?.add(hudson.model.Item.CANCEL,sID)
authorizationMatrixProperty?.add(Item.WORKSPACE,sID);
authorizationMatrixProperty?.add(Item.BUILD,sID);
authorizationMatrixProperty?.add(Run.DELETE,sID);
authorizationMatrixProperty?.add(Run.UPDATE,sID);
authorizationMatrixProperty?.add(Item.CONFIGURE,sID);
authorizationMatrixProperty?.add(Item.DELETE,sID);
authorizationMatrixProperty?.add(Item.READ,sID);
item.addProperty( authorizationMatrixProperty )
item.save()
}
}
Thanks and best regards,
Achala M. Rathnathilaka
Java software Enginner,
Sri Lanka.
On Tuesday, 12 July 2011 17:32:32 UTC+5:30, RainerW wrote:
I using a Jenkin s1.409.1 and try to change the Security Settings for
a bunch of projects via an groovy script [SCRIPT].
The script runs on the Master ( via "Manage Jenkins"\"Script
Console" ). All matching projects seemed to have beed modified : E.g.
the Job configuration dialog shows the changed Authorization Matrix,
and the %JOB%/config.xml file is updated.
Only Jenkins doesn't seem to get it. The "build" user (The one now
should have rights) still isn't seeing the project. I can relogin,
reload / restart Jenkins (Winstone), nothing changes.
When i just press the save button in the job configuration ... magic
happens. Now the the security has been updated, the build user can see
the project immediately.
So what did i miss? Which magic does the save Button, which i'm not
doing?
Cheers Rainer
SCRIPT:
import hudson.security.*
import hudson.model.*
items = hudson.model.Hudson.instance.items;
for (job in items) {
if (job.name.matches("INTER.*")) {
println("JOB: " + job)
props = job.properties;
a = new AuthorizationMatrixProperty();
// QA group, 're-add' coz there is only one property for all
users
user = "qa"
a.add(Item.WORKSPACE,user);
a.add(Item.BUILD,user);
a.add(Run.DELETE,user);
a.add(Run.UPDATE,user);
a.add(Item.CONFIGURE,user);
a.add(Item.DELETE,user);
a.add(Item.READ,user);
// Build User
user = "build"
a.add(Item.WORKSPACE,user);
a.add(Item.BUILD,user);
// a.add(Run.DELETE,user);
a.add(Run.UPDATE,user);
a.add(Item.CONFIGURE,user);
a.add(Item.DELETE,user);
a.add(Item.READ,user);
// save it
job.addProperty( a )
job.save()
}
}
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/b09a309b-9503-42c3-9cc5-78ff52161b57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/DIIE.00002D8600743873%40192.168.11.6.
For more options, visit https://groups.google.com/d/optout.