Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #543 from stephenc/jenkins-47526
[JENKINS-47526] Provide an API to allow an AbstractGitSCMSource to work at a distance from the repository rather than requiring a local checkout
  • Loading branch information
MarkEWaite committed Oct 23, 2017
2 parents c5fbe73 + f7f9310 commit a82b46d
Show file tree
Hide file tree
Showing 4 changed files with 1,221 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -18,6 +18,8 @@
import hudson.model.*;
import hudson.model.Descriptor.FormException;
import hudson.model.Hudson.MasterComputer;
import hudson.model.Queue;
import hudson.model.queue.Tasks;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.extensions.GitClientConflictException;
import hudson.plugins.git.extensions.GitClientType;
Expand Down Expand Up @@ -762,8 +764,14 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
String ucCredentialsId = uc.getCredentialsId();
if (ucCredentialsId != null) {
String url = getParameterString(uc.getUrl(), environment);
List<StandardUsernameCredentials> urlCredentials = CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, project,
ACL.SYSTEM, URIRequirementBuilder.fromUri(url).build());
List<StandardUsernameCredentials> urlCredentials = CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
project,
project instanceof Queue.Task
? Tasks.getDefaultAuthenticationOf((Queue.Task)project)
: ACL.SYSTEM,
URIRequirementBuilder.fromUri(url).build()
);
CredentialsMatcher ucMatcher = CredentialsMatchers.withId(ucCredentialsId);
CredentialsMatcher idMatcher = CredentialsMatchers.allOf(ucMatcher, GitClient.CREDENTIALS_MATCHER);
StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(urlCredentials, idMatcher);
Expand Down

0 comments on commit a82b46d

Please sign in to comment.