diff --git a/src/main/java/hudson/plugins/git/GitSCM.java b/src/main/java/hudson/plugins/git/GitSCM.java index 085c0f5670..aafbf2c6af 100644 --- a/src/main/java/hudson/plugins/git/GitSCM.java +++ b/src/main/java/hudson/plugins/git/GitSCM.java @@ -42,7 +42,6 @@ import hudson.scm.RepositoryBrowser; import hudson.scm.SCMDescriptor; import hudson.scm.SCMRevisionState; -import hudson.security.ACL; import hudson.security.Permission; import hudson.tasks.Builder; import hudson.tasks.Publisher; @@ -712,7 +711,7 @@ private PollingResult compareRemoteRevisionWithImpl(Job project, Launcher final EnvVars environment = project instanceof AbstractProject ? GitUtils.getPollEnvironment((AbstractProject) project, workspace, launcher, listener, false) : new EnvVars(); - GitClient git = createClient(listener, environment, project, Jenkins.get(), null); + GitClient git = createClient(listener, environment, lastBuild, Jenkins.get(), null); for (RemoteConfig remoteConfig : getParamExpandedRepos(lastBuild, listener)) { String remote = remoteConfig.getName(); @@ -788,7 +787,7 @@ private PollingResult compareRemoteRevisionWithImpl(Job project, Launcher return BUILD_NOW; } - GitClient git = createClient(listener, environment, project, node, workingDirectory); + GitClient git = createClient(listener, environment, lastBuild, node, workingDirectory); if (git.hasGitRepo(false)) { // Repo is there - do a fetch @@ -829,13 +828,13 @@ private PollingResult compareRemoteRevisionWithImpl(Job project, Launcher * @throws InterruptedException when interrupted */ @NonNull - public GitClient createClient(TaskListener listener, EnvVars environment, Run build, FilePath workspace) throws IOException, InterruptedException { + public GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run build, FilePath workspace) throws IOException, InterruptedException { FilePath ws = workingDirectory(build.getParent(), workspace, environment, listener); /* ws will be null if the node which ran the build is offline */ if (ws != null) { ws.mkdirs(); // ensure it exists } - return createClient(listener,environment, build.getParent(), GitUtils.workspaceToNode(workspace), ws, null); + return createClient(listener,environment, build, GitUtils.workspaceToNode(workspace), ws, null); } /** @@ -852,23 +851,23 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run build, FilePath workspace, UnsupportedCommand postBuildUnsupportedCommand) throws IOException, InterruptedException { + public GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run build, FilePath workspace, UnsupportedCommand postBuildUnsupportedCommand) throws IOException, InterruptedException { FilePath ws = workingDirectory(build.getParent(), workspace, environment, listener); /* ws will be null if the node which ran the build is offline */ if (ws != null) { ws.mkdirs(); // ensure it exists } - return createClient(listener,environment, build.getParent(), GitUtils.workspaceToNode(workspace), ws, postBuildUnsupportedCommand); + return createClient(listener,environment, build, GitUtils.workspaceToNode(workspace), ws, postBuildUnsupportedCommand); } @NonNull - /*package*/ GitClient createClient(TaskListener listener, EnvVars environment, Job project, Node n, FilePath ws) throws IOException, InterruptedException { - return createClient(listener, environment, project, n, ws, null); + private GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run build, Node n, FilePath ws) throws IOException, InterruptedException { + return createClient(listener, environment, build, n, ws, null); } @NonNull - /*package*/ GitClient createClient(TaskListener listener, EnvVars environment, Job project, Node n, FilePath ws, UnsupportedCommand postBuildUnsupportedCommand) throws IOException, InterruptedException { + private GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run build, Node n, FilePath ws, UnsupportedCommand postBuildUnsupportedCommand) throws IOException, InterruptedException { if (postBuildUnsupportedCommand == null) { /* UnsupportedCommand supports JGit by default */ @@ -890,7 +889,7 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run build, @CheckForNull String url, @CheckForNull String ucCredentialsId) { if (Util.fixEmpty(ucCredentialsId) == null) { return null; } else { - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentials( - StandardUsernameCredentials.class, - project, - project instanceof Queue.Task - ? ((Queue.Task) project).getDefaultAuthentication() - : ACL.SYSTEM, - URIRequirementBuilder.fromUri(url).build() - ), - CredentialsMatchers.allOf(CredentialsMatchers.withId(ucCredentialsId), GitClient.CREDENTIALS_MATCHER) - ); + StandardUsernameCredentials c = CredentialsProvider.findCredentialById( + ucCredentialsId, + StandardUsernameCredentials.class, + build, + URIRequirementBuilder.fromUri(url).build()); + return c != null && GitClient.CREDENTIALS_MATCHER.matches(c) ? c : null; } }