|
12 | 12 | import hudson.model.AbstractDescribableImpl; |
13 | 13 | import hudson.model.Descriptor; |
14 | 14 | import hudson.model.Item; |
| 15 | +import hudson.model.ItemGroup; |
15 | 16 | import hudson.security.ACL; |
16 | 17 | import hudson.security.AccessControlled; |
17 | 18 | import hudson.util.FormValidation; |
@@ -228,22 +229,32 @@ public String getCredentialsId() { |
228 | 229 | */ |
229 | 230 | public PersonalAccessToken getCredentials(AccessControlled context) { |
230 | 231 | Jenkins jenkins = Jenkins.get(); |
231 | | - AccessControlled item; |
232 | 232 | if (context == null) { |
233 | 233 | jenkins.checkPermission(CredentialsProvider.USE_OWN); |
234 | | - item = jenkins; |
| 234 | + return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
| 235 | + PersonalAccessToken.class, |
| 236 | + jenkins, |
| 237 | + ACL.SYSTEM, |
| 238 | + fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
| 239 | + ), withId(credentialsId)); |
235 | 240 | } else { |
236 | 241 | context.checkPermission(CredentialsProvider.USE_OWN); |
237 | | - item = context; |
| 242 | + if (context instanceof ItemGroup) { |
| 243 | + return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
| 244 | + PersonalAccessToken.class, |
| 245 | + (ItemGroup) context, |
| 246 | + ACL.SYSTEM, |
| 247 | + fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
| 248 | + ), withId(credentialsId)); |
| 249 | + } else { |
| 250 | + return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
| 251 | + PersonalAccessToken.class, |
| 252 | + (Item) context, |
| 253 | + ACL.SYSTEM, |
| 254 | + fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
| 255 | + ), withId(credentialsId)); |
| 256 | + } |
238 | 257 | } |
239 | | - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( |
240 | | - lookupCredentials( |
241 | | - PersonalAccessToken.class, |
242 | | - (Item) item, |
243 | | - ACL.SYSTEM, |
244 | | - fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
245 | | - ), withId(credentialsId)); |
246 | | - |
247 | 258 | } |
248 | 259 |
|
249 | 260 | /** |
|
0 commit comments