Skip to content

Commit

Permalink
JENKINS-35983 - Add support to job import jobs in folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Evildethow committed Jul 4, 2016
1 parent 2b4a0f9 commit d33a547
Show file tree
Hide file tree
Showing 19 changed files with 1,025 additions and 186 deletions.
14 changes: 13 additions & 1 deletion pom.xml
Expand Up @@ -45,7 +45,7 @@
<url>http://wiki.jenkins-ci.org/display/JENKINS/Job+Import+Plugin</url>

<properties>
<jenkins.version>1.580</jenkins.version>
<jenkins.version>1.609.1</jenkins.version>
<java.level>6</java.level>
<findbugs.failOnError>false</findbugs.failOnError>
</properties>
Expand Down Expand Up @@ -103,6 +103,18 @@
<artifactId>credentials</artifactId>
<version>1.24</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.12</version>
</dependency>

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.58</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,59 @@
package org.jenkins.ci.plugins.jobimport;

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.google.common.base.Strings;
import hudson.model.Item;
import hudson.security.ACL;

import java.util.Collections;
import java.util.List;

import static com.google.inject.internal.guava.base.$Preconditions.checkNotNull;

/**
* Created by evildethow on 28/06/2016.
*/
final class CredentialsUtils {

private CredentialsUtils() {
throw new UnsupportedOperationException("Cannot instantiate utility class");
}

static NullSafeCredentials getCredentials(String credentialId) {
if (!Strings.isNullOrEmpty(credentialId)) {
StandardUsernamePasswordCredentials cred = CredentialsMatchers.firstOrNull(allCredentials(), CredentialsMatchers.withId(credentialId));
if (cred != null) {
return new NullSafeCredentials(cred.getUsername(), cred.getPassword().getPlainText());
}
}
return new NullSafeCredentials();
}

static List<StandardUsernamePasswordCredentials> allCredentials() {
return CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class,
(Item) null,
ACL.SYSTEM,
Collections.<DomainRequirement>emptyList()
);
}

static final class NullSafeCredentials {

final String username;
final String password;

NullSafeCredentials(String username, String password) {
this.username = checkNotNull(username);
this.password = checkNotNull(password);
}

NullSafeCredentials() {
this.username = "";
this.password = "";
}
}
}

0 comments on commit d33a547

Please sign in to comment.