Skip to content

Commit

Permalink
[JENKINS-35540] Upgrade to Credentials 2.1.0+ API for populating cred…
Browse files Browse the repository at this point in the history
…entials drop-down (#21)

* [JENKINS-35540] upgraded to credentials 2.1.x
* added Jenkinsfile
* [JENKINS-35540] adding also user crendentials
  • Loading branch information
escoem committed Oct 26, 2017
1 parent c38afcd commit e05b69d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
@@ -0,0 +1 @@
buildPlugin()
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -106,12 +106,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.24</version>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.12</version>
<version>6.0.4</version>
</dependency>

<dependency>
Expand Down
Expand Up @@ -24,13 +24,18 @@

package org.jenkins.ci.plugins.jobimport;

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.RootAction;
import hudson.model.TopLevelItem;
import hudson.security.ACL;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
Expand All @@ -52,6 +57,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
Expand Down Expand Up @@ -272,9 +278,21 @@ public static final class JobImportActionDescriptor extends Descriptor<JobImport
public String getDisplayName() { return ""; }

public ListBoxModel doFillCredentialIdItems() {
return new StandardUsernameListBoxModel()
.withEmptySelection()
.withAll(allCredentials());
return new StandardListBoxModel()
.includeEmptyValue()
.includeMatchingAs(
Jenkins.getAuthentication(),
Jenkins.getInstance(),
StandardUsernamePasswordCredentials.class,
Collections.<DomainRequirement>emptyList(),
CredentialsMatchers.always()
).includeMatchingAs(
ACL.SYSTEM,
Jenkins.getInstance(),
StandardUsernamePasswordCredentials.class,
Collections.<DomainRequirement>emptyList(),
CredentialsMatchers.always()
);
}
}
}
Expand Up @@ -30,6 +30,7 @@ public static NullSafeCredentials getCredentials(String credentialId) {
return new NullSafeCredentials();
}

@Deprecated
public static List<StandardUsernamePasswordCredentials> allCredentials() {
return CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class,
Expand Down

0 comments on commit e05b69d

Please sign in to comment.