/** * Expand Parameters in the supplied remote repository with the parameter values provided in the given environment variables } * @param env Environment variables with parameter values * @param remoteRepository Remote repository with parameters * @return remote repository with expanded parameters */ public RemoteConfig getParamExpandedRepo(EnvVars env, RemoteConfig remoteRepository){ List<RefSpec> refSpecs = getRefSpecs(remoteRepository, env); return newRemoteConfig( getParameterString(remoteRepository.getName(), env), getParameterString(remoteRepository.getURIs().get(0).toPrivateString(), env), refSpecs.toArray(new RefSpec[refSpecs.size()])); }
private List<RefSpec> getRefSpecs(RemoteConfig repo, EnvVars env) { List<RefSpec> refSpecs = new ArrayList<>(); for (RefSpec refSpec : repo.getFetchRefSpecs()) { refSpecs.add(new RefSpec(getParameterString(refSpec.toString(), env))); } return refSpecs; }
/** * Gets the parameter-expanded effective value in the context of the current build. * @param build run whose local branch name is returned * @param listener build log * @throws IOException on input or output error * @throws InterruptedException when interrupted * @return parameter-expanded local branch name in build. */ public String getParamLocalBranch(Run<?, ?> build, TaskListener listener) throws IOException, InterruptedException { String branch = getLocalBranch(); // substitute build parameters if available return getParameterString(branch != null ? branch : null, build.getEnvironment(listener)); }
branch = getParameterString(branch, env);
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException { String remoteBranchRef = GitSCM.getParameterString(options.getRef(), build.getEnvironment(listener));
@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; }