为了演示方便,我这里创建了如下的一些任务,各个任务由包含在对应的目录中树形结构大概如下:
jenkins-authority 目录类型任务
├── dev-project-group 目录类型任务
│ ├── dev-account-service 自由风格任务
│ └── dev-message-service 自由风格任务
├── prod-project-group 目录类型任务
│ ├── prod-account-service 自由风格任务
│ └── prod-message-service 自由风格任务
└── test-project-group 目录类型任务
├── test-account-service 自由风格任务
└── test-message-service 自由风格任务

最后分别用张三、李四、王五账号登录到 Jenkins 系统看看权限设置的效果。没有意外的话王五是运维人员角色可以构建和管理 dev、test 和 prod 的任务,李四只能构建和管理 test 的任务,张三只能管理和构建 dev 的任务。并且张三、李四也只能在对应的环境目录下创建新的任务,不能在其他目录创建任务。
用开发组张三账号登陆到 Jenkins ,去到 dev-project-group 目录和下面的具体某个任务下面,看到左侧的菜单栏可以进行修改编辑操作。


如果张三去到测试项目组 test-project-group 和目录下的具体某个任务,可以看到左侧的菜单栏是没法进行编辑和构建操作的。


然后可以在用测试组账号李四登陆到 Jenkins 看看是什么样的效果:





王五为运维角色,可以管理 dev、test、prod 组的任务:




经过上面的配置,我们的 Jenkins 权限管控就相对精细并且也符合我们的要求和预期了。其实除了对任务进行权限控制外还可以对 Jenkins 节点进行权限控制,只是一般用不到,并且节点最好是都允许进行任务在上面进行构建执行,否则节点的压力负载分担就会出问题。
|