Skip to content

Commit

Permalink
add dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce.wu committed Dec 17, 2024
1 parent 9f66044 commit cff6265
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/io/jenkins/plugins/blueking/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import hudson.model.ItemGroup;
import java.util.Collections;
import java.util.Objects;
import jenkins.model.Jenkins;
Expand All @@ -23,13 +24,16 @@ public static boolean isNotEmpty(final String name) {
}

public static <T extends StandardCredentials> T findCredential(String credentialsId, Class<T> clazz) {
StandardCredentials credentials = null;
return findCredential(credentialsId, null, clazz);
}

public static <T extends StandardCredentials> T findCredential(
String credentialsId, ItemGroup<?> itemGroup, Class<T> clazz) {
if (Utils.isNullOrEmpty(credentialsId)) {
return null;
}

for (T c :
CredentialsProvider.lookupCredentialsInItemGroup(clazz, Jenkins.get(), null, Collections.emptyList())) {
for (T c : CredentialsProvider.lookupCredentialsInItemGroup(
clazz, Objects.requireNonNullElse(itemGroup, Jenkins.get()), null, Collections.emptyList())) {
if (Objects.equals(c.getId(), credentialsId)) {
return c;
}
Expand Down

0 comments on commit cff6265

Please sign in to comment.