在使用播种机作业创建Jenkins文件夹时,如何设置其所有者? [英] How to set the owner of a Jenkins folder when creating it with a seeder job?

查看:85
本文介绍了在使用播种机作业创建Jenkins文件夹时,如何设置其所有者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Job DSL插件创建文件夹,其中包含预定义的作业集合.我还使用所有权插件来控制哪些用户可以访问每个文件夹.

I've written a seeder job using the Job DSL Plugin to create folders with a predefined collection of jobs inside. I also use the Ownership Plugin to control which users get access to each folder.

现在,我需要将触发种子作业的用户分配为文件夹的主要所有者.

Now I need the user who fired the seeder job to be assigned as the folder's primary owner.

我尝试设置将工作创建者分配为所有者"配置选项,但结果是创建的文件夹的所有者为SYSTEM.

I tried setting "Assign job creators as owners" configuration option, but the result I get is that the created folder's owner is SYSTEM.

是否可以通过编程方式设置文件夹的主要所有者?

Is there a way to programmatically set the primary owner of the folder programmatically?

推荐答案

最后,我能够通过获取当前用法的名称作为currentBuild变量的Cause并将其分配给像这样使用configure步骤来复制文件夹:

In the end I was able to do this by getting the name of the current use as the Cause of the currentBuild variable and then assign it to the folder by using the configure step like so:

user = currentBuild.getCause(Cause.UserIdCause)
folder("MyFolder") {
    configure { folder ->
        folder / 'properties' / 'org.jenkinsci.plugins.ownership.model.folders.FolderOwnershipProperty' / 'ownership' {     
            primaryOwnerId(user.getUserId())
            ownershipEnabled('true')
        }
    }
}

如果任何人都可以提供一个不太冗长的方法来完成此操作,则将其标记为可接受的答案.

If anyone can provide a less verbose way to do this I'll mark that as the accepted answer.

这篇关于在使用播种机作业创建Jenkins文件夹时,如何设置其所有者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆