aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Epishchev <epishev@garant.ru>2016-02-01 12:15:56 +0300
committerMaxim Epishchev <epishev@garant.ru>2016-02-01 12:15:56 +0300
commitb2e2b808c9155e78a9c6244d89b57ee9a0f32c90 (patch)
tree4786a0d6b4a177dc2653d909cfd5952c2e5fe0a3
parent96ab7a75f14d9990f3c8f1255f9790c496a64473 (diff)
parentf0588fb15ee687619695bccfc7553dbcd43b948d (diff)
downloadbbprb-b2e2b808c9155e78a9c6244d89b57ee9a0f32c90.tar.gz
Merge branch 'CredentialsSupport' of https://github.com/kadaan/bitbucket-pullrequest-builder-plugin into CredentialsSupport
Conflicts: .gitignore src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
-rw-r--r--.gitignore5
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java21
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java25
-rw-r--r--src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly5
4 files changed, 52 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 2f7896d..3c7b603 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
-target/
+target
+*.iml
+.idea
+dependency-reduced-pom.xml
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
index cd9345c..2375ec7 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java
@@ -1,12 +1,17 @@
package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder;
import antlr.ANTLRException;
+import com.cloudbees.plugins.credentials.CredentialsProvider;
+import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
+import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
+import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
import hudson.Extension;
import hudson.model.*;
import hudson.model.queue.QueueTaskFuture;
import hudson.plugins.git.RevisionParameterAction;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
+import hudson.util.ListBoxModel;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
@@ -17,6 +22,8 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
+import static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf;
+
/**
* Created by nishio
*/
@@ -24,6 +31,7 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
private static final Logger logger = Logger.getLogger(BitbucketBuildTrigger.class.getName());
private final String projectPath;
private final String cron;
+ private final String credentialsId;
private final String username;
private final String password;
private final String repositoryOwner;
@@ -45,6 +53,7 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
public BitbucketBuildTrigger(
String projectPath,
String cron,
+ String credentialsId,
String username,
String password,
String repositoryOwner,
@@ -60,6 +69,7 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
super(cron);
this.projectPath = projectPath;
this.cron = cron;
+ this.credentialsId = credentialsId;
this.username = username;
this.password = password;
this.repositoryOwner = repositoryOwner;
@@ -81,6 +91,10 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
return this.cron;
}
+ public String getCredentialsId() {
+ return credentialsId;
+ }
+
public String getUsername() {
return username;
}
@@ -208,5 +222,12 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> {
save();
return super.configure(req, json);
}
+
+ public ListBoxModel doFillCredentialsIdItems() {
+ return new StandardListBoxModel()
+ .withEmptySelection()
+ .withMatching(instanceOf(UsernamePasswordCredentials.class),
+ CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class));
+ }
}
}
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index 6736ee9..d8c736e 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -13,12 +13,18 @@ import java.util.LinkedList;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import com.cloudbees.plugins.credentials.CredentialsMatchers;
+import com.cloudbees.plugins.credentials.CredentialsProvider;
+import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
+import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
import jenkins.model.Jenkins;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.SCMSourceOwners;
import org.apache.commons.lang.StringUtils;
+static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf;
+
/**
* Created by nishio
*/
@@ -46,9 +52,16 @@ public class BitbucketRepository {
public void init(ApiClient client) {
this.trigger = this.builder.getTrigger();
+ String username = trigger.getUsername();
+ String password = trigger.getPassword();
+ StandardUsernamePasswordCredentials credentials = getCredentials(trigger.getCredentialsId());
+ if (credentials != null) {
+ username = credentials.getUsername();
+ password = credentials.getPassword().getPlainText();
+ }
this.client = (client == null) ? new ApiClient(
- trigger.getUsername(),
- trigger.getPassword(),
+ username,
+ password,
trigger.getRepositoryOwner(),
trigger.getRepositoryName(),
trigger.getCiKey(),
@@ -267,4 +280,12 @@ public class BitbucketRepository {
return filter.approved(cause);
}
+
+ private StandardUsernamePasswordCredentials getCredentials(String credentialsId) {
+ return CredentialsMatchers
+ .firstOrNull(
+ CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class),
+ CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId),
+ instanceOf(UsernamePasswordCredentials.class)));
+ }
}
diff --git a/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly b/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
index 25acac0..d4b23da 100644
--- a/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
+++ b/src/main/resources/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger/config.jelly
@@ -1,7 +1,10 @@
-<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:c="/lib/credentials">
<f:entry title="Cron" field="cron">
<f:textbox />
</f:entry>
+ <f:entry title="${%Credentials}" field="credentialsId">
+ <c:select/>
+ </f:entry>
<f:entry title="Bitbucket BasicAuth Username" field="username">
<f:textbox />
</f:entry>