/** * Constructor for GitAPI. * * @param gitExe name of git executable (git or git.exe or jgit) * @param repository a {@link hudson.FilePath} for the repository directory * @param listener a {@link hudson.model.TaskListener} which monitors the git work * @param environment the {@link hudson.EnvVars} environment for the build * @throws java.io.IOException if any IO failure * @throws java.lang.InterruptedException if interrupted. */ @Deprecated public GitAPI(String gitExe, File repository, TaskListener listener, EnvVars environment) throws IOException, InterruptedException { super(gitExe, repository, listener, environment); // If USE_CLI is forced, don't delegate to JGit client this.jgit = Git.USE_CLI ? null : Git.with(listener, environment).in(repository).using("jgit").getClient(); }
@Override public Boolean invoke(File localWorkspace, VirtualChannel channel) throws IOException, InterruptedException { File gitClonePath = localWorkspace; if (gitPrefix != null) { gitClonePath = new File(localWorkspace, gitPrefix); } GitClient git = Git.with(listener, environment) .in(gitClonePath).using(gitExe) .getClient(); if (git.hasGitRepo()) { PersonIdent person = new PersonIdent(accountName, accountEmail); for (String module: modules) { git.add(new File(module, "debian/changelog").getCanonicalPath()); } git.setAuthor(person); git.setCommitter(person); git.commit(commitMessage); return true; } else { return false; } }
.using(GitTool.getDefaultInstallation().getGitExe()) .getClient(); StandardCredentials credential = lookupCredentials(item, credentialsId, url);
GitTool tool = resolveGitTool(context.gitTool()); if (tool != null) { git.using(tool.getGitExe());
GitTool tool = gitSCMSource.resolveGitTool(builder.gitTool()); if (tool != null) { git.using(tool.getGitExe());
GitTool tool = gitSCM.resolveGitTool(listener); if (tool != null) { git.using(tool.getGitExe());
@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; }
private GitClient getGitClient(ReleaseRepository releaseRepository) throws IOException, InterruptedException { FilePath directory = getWorkingDirectory(getJenkinsScm(), build.getWorkspace()); EnvVars env = build.getEnvironment(buildListener); Git git = new Git(buildListener, env); git.in(directory); /* * When init the git exe, the user dons`t have to add SSH credentials in the git plugin. * This solution automatically takes the user default SSH ($HOME/.ssh) * */ git.using(getJenkinsScm().getGitExe(build.getBuiltOn(), buildListener)); // git.exe GitClient client = git.getClient(); client.setCommitter(StringUtils.defaultIfEmpty(env.get("GIT_COMMITTER_NAME"), ""), StringUtils.defaultIfEmpty(env.get("GIT_COMMITTER_EMAIL"), "")); client.setAuthor(StringUtils.defaultIfEmpty(env.get("GIT_AUTHOR_NAME"), ""), StringUtils.defaultIfEmpty(env.get("GIT_AUTHOR_EMAIL"), "")); if (releaseRepository != null && releaseRepository.isTargetRepoUri()) { client.setRemoteUrl(releaseRepository.getRepositoryName(), releaseRepository.getTargetRepoPrivateUri()); } else { addRemoteRepoToConfig(client); } addCredentialsToGitClient(client); return client; }