diff options
author | Maxim Epishchev <epishev@garant.ru> | 2016-02-01 12:15:56 +0300 |
---|---|---|
committer | Maxim Epishchev <epishev@garant.ru> | 2016-02-01 12:15:56 +0300 |
commit | b2e2b808c9155e78a9c6244d89b57ee9a0f32c90 (patch) | |
tree | 4786a0d6b4a177dc2653d909cfd5952c2e5fe0a3 /src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java | |
parent | 96ab7a75f14d9990f3c8f1255f9790c496a64473 (diff) | |
parent | f0588fb15ee687619695bccfc7553dbcd43b948d (diff) | |
download | bbprb-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
Diffstat (limited to 'src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java')
-rw-r--r-- | src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java | 25 |
1 files changed, 23 insertions, 2 deletions
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))); + } } |