I need to add some permissions (Read, Build, Workspace, cancel etc) to a spesific user to a lot of jobs. I'm wondering it there is a way to do that using groovy script instead of doing it manually.
相关问题
- Grails External Configuration. Can't access to
- Jenkins - cmd is not recognized
- When using Nokogiri, how do you suppress the inser
- Where Jenkins stores plugin configuration
- Multi-branch configuration with externally-defined
相关文章
- dotnet restore还原nuget包时无法加载 https://api.nuget.org/
- jenkins在window集群环境中如何部署自动化发布?
- jenkins + Publish over FTP 自动部署前端React项目
- jenkins自定打包部署React前端项目遇到的问题。
- Best way to manage docker containers with supervis
- Using Spring Dynamic Languages Support from Groovy
- Access BitBucket payload data in Jenkins pipeline
- Jenkins Not Outputting Junit Report Info From File
We don't need to create new permission object, just create new hudson.security.AuthorizationMatrixProperty:
where "hudson.model.Item.Build:DEV" is a permission string you can take from xml file with configured permissions you need
As far as I know what you are trying to do is not possible.
Link: https://wiki.jenkins-ci.org/display/JENKINS/Matrix-based+security
I would recommend using 'configuration slicing' if there is a change that you want to apply to multiple jobs at the same time.
https://wiki.jenkins-ci.org/display/JENKINS/Configuration+Slicing+Plugin
but i don't think permissions are part of configuration slicing anyway.
You can use the execute system groovy step to run a script like:
(if you figure out how to get a permission object without reading it from a different job, please update)
I tried the above solutions, and they nearly worked. All my attempts resulted in the current, in-memory permissions reflecting the new settings, but those permissions were not saved in config.xml, so when Jenkins was restarted the permissions were lost. Building on Andrew Hura's solution, I came up with this code, which works across a restart:
Have a look a the script here: https://github.com/MovingBlocks/GroovyJenkins/blob/master/src/main/groovy/ChangeSecurityPerJob.groovy
You should be able to pull parts of it out to do what you want, kinda like this.
The more interesting part is if you need to merge the permissions.
You can find example for that in the above link as well.