diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 6ad401c6a..1f99b53d9 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -138,6 +138,8 @@ def authenticated_build(parser, xml_parent, data): Specifies an authorization matrix where only authenticated users may trigger a build. + DEPRECATED + Example:: properties: @@ -151,6 +153,64 @@ def authenticated_build(parser, xml_parent, data): 'hudson.model.Item.Build:authenticated' +def authorization(parser, xml_parent, data): + """yaml: authorization + Specifies an authorization matrix + + The available rights are: + job-delete + job-configure + job-read + job-discover + job-build + job-workspace + job-cancel + run-delete + run-update + scm-tag + + Example:: + + properties: + - authorization: + admin: + - job-delete + - job-configure + - job-read + - job-discover + - job-build + - job-workspace + - job-cancel + - run-delete + - run-update + - scm-tag + anonymous: + - job-discover + - job-read + """ + + mapping = { + 'job-delete': 'hudson.model.Item.Delete', + 'job-configure': 'hudson.model.Item.Configure', + 'job-read': 'hudson.model.Item.Read', + 'job-discover': 'hudson.model.Item.Discover', + 'job-build': 'hudson.model.Item.Build', + 'job-workspace': 'hudson.model.Item.Workspace', + 'job-cancel': 'hudson.model.Item.Cancel', + 'run-delete': 'hudson.model.Run.Delete', + 'run-update': 'hudson.model.Run.Update', + 'scm-tag': 'hudson.scm.SCM.Tag' + } + + if data: + matrix = XML.SubElement(xml_parent, + 'hudson.security.AuthorizationMatrixProperty') + for (username, perms) in data.items(): + for perm in perms: + pe = XML.SubElement(matrix, 'permission') + pe.text = "{0}:{1}".format(mapping[perm], username) + + class Properties(jenkins_jobs.modules.base.Base): sequence = 20 diff --git a/setup.py b/setup.py index 88331e7fc..298aaf7c1 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ setup(name='jenkins_job_builder', 'inject=jenkins_jobs.modules.properties:inject', 'authenticated-build=jenkins_jobs.modules.properties:' 'authenticated_build', + 'authorization=jenkins_jobs.modules.properties:authorization', ], 'jenkins_jobs.parameters': [ 'string=jenkins_jobs.modules.parameters:string_param',