public BuildData(String scmName, Collection<UserRemoteConfig> remoteConfigs) { this.scmName = scmName; for(UserRemoteConfig c : remoteConfigs) { remoteUrls.add(c.getUrl()); } }
private boolean isRelevantBuildData(BuildData bd) { for(UserRemoteConfig c : getUserRemoteConfigs()) { if(bd.hasBeenReferenced(c.getUrl())) { return true; } } return false; }
public String toString() { return getRefspec() + " => " + getUrl() + " (" + getName() + ")"; }
private void updateFromUserData() throws GitException { // do what newInstance used to do directly from the request data if (userRemoteConfigs == null) { return; /* Prevent NPE when no remote config defined */ } try { String[] pUrls = new String[userRemoteConfigs.size()]; String[] repoNames = new String[userRemoteConfigs.size()]; String[] refSpecs = new String[userRemoteConfigs.size()]; for (int i = 0; i < userRemoteConfigs.size(); ++i) { pUrls[i] = userRemoteConfigs.get(i).getUrl(); repoNames[i] = userRemoteConfigs.get(i).getName(); refSpecs[i] = userRemoteConfigs.get(i).getRefspec(); } this.remoteRepositories = DescriptorImpl.createRepositoryConfigurations(pUrls, repoNames, refSpecs); // TODO: replace with new repositories } catch (IOException e1) { throw new GitException("Error creating repositories", e1); } }
private Boolean repoMatches(final GitCodePushedEventArgs gitCodePushedEventArgs, final Job job) { if (job instanceof WorkflowJob) { final FlowDefinition jobDef = ((WorkflowJob) job).getDefinition(); if (jobDef instanceof CpsScmFlowDefinition) { final SCM jobSCM = ((CpsScmFlowDefinition) jobDef).getScm(); if (jobSCM instanceof GitSCM) { final GitSCM gitJobSCM = (GitSCM) jobSCM; final URIish uri = gitCodePushedEventArgs.getRepoURIish(); for (final UserRemoteConfig remoteConfig : gitJobSCM.getUserRemoteConfigs()) { final String jobRepoUrl = remoteConfig.getUrl(); if (StringUtils.equalsIgnoreCase(jobRepoUrl, uri.toString())) { return true; } } } } } return false; }
/** * Returns a List of Pair<key, value> which contains the git credentials to use. * Key - url to repository * Value - StandardCredentials, containing username and password */ private List<Pair<String, StandardCredentials>> getGitClientCredentials() { List<Pair<String, StandardCredentials>> credentialsList = new ArrayList<>(); GitSCM gitScm = getJenkinsScm(); for (UserRemoteConfig uc : gitScm.getUserRemoteConfigs()) { String url = uc.getUrl(); // In case overriding credentials are defined, we will use it for this URL if (this.credentials != null) { credentialsList.add(Pair.of(url, this.credentials)); continue; } // Get credentials from jenkins credentials plugin if (uc.getCredentialsId() != null) { StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, build.getProject(), ACL.SYSTEM, URIRequirementBuilder.fromUri(url).build()), CredentialsMatchers.allOf(CredentialsMatchers.withId(uc.getCredentialsId()), GitClient.CREDENTIALS_MATCHER)); if (credentials != null) { credentialsList.add(Pair.of(url, (StandardCredentials)credentials)); } } } return credentialsList; }
UserRemoteConfig config = gitSCM.getUserRemoteConfigs().get(0); BranchSpec branchSpec = gitSCM.getBranches().get(0); String remote = config.getUrl(); String cacheEntry = AbstractGitSCMSource.getCacheEntry(remote); Lock cacheLock = AbstractGitSCMSource.getCacheLock(cacheEntry);
@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; }