@Override public boolean supports(SCM source) { return source instanceof GitSCM && ((GitSCM) source).getUserRemoteConfigs().size() == 1 && ((GitSCM) source).getBranches().size() == 1 && ((GitSCM) source).getBranches().get(0).getName().matches( "^((\\Q" + Constants.R_HEADS + "\\E.*)|([^/]+)|(\\*/[^/*]+(/[^/*]+)*))$" ); // we only support where the branch spec is obvious }
private boolean isRelevantBuildData(BuildData bd) { for(UserRemoteConfig c : getUserRemoteConfigs()) { if(bd.hasBeenReferenced(c.getUrl())) { return true; } } return false; }
for (final UserRemoteConfig remote : getUserRemoteConfigs()) { remoteName = remote.getName(); if (remoteName == null || remoteName.isEmpty()) {
@NonNull private BuildData fixNull(BuildData bd) { return bd != null ? bd : new BuildData(getScmName(), getUserRemoteConfigs()) /*dummy*/; }
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; }
@Override public GitSCM createScm(GitHubSCMSource scmSource, SCMHead scmHead, SCMRevision scmRevision) { return new GitSCM( gitSCM.getUserRemoteConfigs(), gitSCM.getBranches(), gitSCM.isDoGenerateSubmoduleConfigurations(), gitSCM.getSubmoduleCfg(), gitSCM.getBrowser(), gitSCM.getGitTool(), gitSCM.getExtensions() ); }
/** * Like {@link #getBuildData(Run)}, but copy the data into a new object, * which is used as the first step for updating the data for the next build. * @param build run whose BuildData is returned * @return copy of build data for build */ public BuildData copyBuildData(Run build) { BuildData base = getBuildData(build); if (base==null) return new BuildData(getScmName(), getUserRemoteConfigs()); else { BuildData buildData = base.clone(); buildData.setScmName(getScmName()); return buildData; } }
UserRemoteConfig config = gitSCM.getUserRemoteConfigs().get(0); BranchSpec branchSpec = gitSCM.getBranches().get(0); String remote = config.getUrl();
@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; }