jenkinsci / jenkinsci/lockable-resources-plugin

Cant set reserve/unlock permissions programmatically

Open
#190 2 comments 0 reactions 0 assignees View on GitHub
documentation good first issue Good for Groovy shared library roles and permissions Triage
Dominant language
Java
Stars
99
Forks
205
Avg merge
2d 13h
Merged PRs (30d)
8

Description

Faced this while trying to automate the Jenkins deployment. I am trying to set permissions for the plugin actions like below

```
import jenkins.*
import jenkins.model.*
import jenkins.model.Jenkins
import hudson.*
import hudson.model.*
import hudson.security.*
import hudson.plugins.git.*
import jenkins.model.Jenkins
import hudson.security.ProjectMatrixAuthorizationStrategy

def instance = Jenkins.getInstance()
println 'Setting up ldap'
String server = 'ldaps://ldap.company1.com'
String rootDN = 'dc=company1,dc=com'
String userSearchBase = ''
String userSearch = 'company1UnixUsername={0}'
String groupSearchBase = ''
String managerDN = ''

String managerPassword = ''
boolean inhibitInferRootDN = false
SecurityRealm ldap_realm = new LDAPSecurityRealm(server, rootDN, userSearchBase, userSearch, groupSearchBase, managerDN, managerPassword, inhibitInferRootDN)

instance.setSecurityRealm(ldap_realm)
def strategy = new ProjectMatrixAuthorizationStrategy()

strategy.add(org.jenkins.plugins.lockableresources.LockableResourcesManager.UNLOCK,'User1name')

instance.setAuthorizationStrategy(strategy)
instance.save()
```
It throws

```
groovy.lang.MissingPropertyException: No such property: UNLOCK for class: org.jenkins.plugins.lockableresources.LockableResourcesManager
at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:1002)
...
```
See full stacktrace attachd

Same error for RESERVE

I've found something very similar[ here in comments](https://issues.jenkins-ci.org/browse/JENKINS-54541) and the answer there was that

> this bug will be covered by that bugfix (PR#117) as well

and as far as i understand that PR has been included into the latest release (2.7) that i'm using currently.

Also i've found [same question at stackexchange](https://stackoverflow.com/questions/57399251/is-there-a-way-of-adding-lockable-resources-permissions-to-a-jenkins-role-via-a)
[JstackTrace.pdf](https://github.com/jenkinsci/lockable-resources-plugin/files/4317826/JstackTrace.pdf)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.