private void addCredentialsToGitClient(GitClient client) { List<Pair<String, StandardCredentials>> credentialsList = getGitClientCredentials(); for (Pair<String, StandardCredentials> entry : credentialsList) { client.addCredentials(entry.getKey(), entry.getValue()); } }
/** {@inheritDoc} */ public void addCredentials(String url, StandardCredentials credentials) { proxy.addCredentials(url, CredentialsProvider.snapshot(StandardCredentials.class, credentials)); // credentials are Serializable }
@NonNull /*package*/ GitClient createClient(TaskListener listener, EnvVars environment, Job project, Node n, FilePath ws) throws IOException, InterruptedException { String gitExe = getGitExe(n, listener); Git git = Git.with(listener, environment).in(ws).using(gitExe); GitClient c = git.getClient(); for (GitSCMExtension ext : extensions) { c = ext.decorate(this,c); } for (UserRemoteConfig uc : getUserRemoteConfigs()) { 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()); CredentialsMatcher ucMatcher = CredentialsMatchers.withId(ucCredentialsId); CredentialsMatcher idMatcher = CredentialsMatchers.allOf(ucMatcher, GitClient.CREDENTIALS_MATCHER); StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(urlCredentials, idMatcher); if (credentials != null) { c.addCredentials(url, credentials); if (project != null && project.getLastBuild() != null) { CredentialsProvider.track(project.getLastBuild(), credentials); } } } } // TODO add default credentials return c; }