/** * Defines the local directory containing the git repository which will be * used. For repositories with a working directory, repository is the parent * of the <code>.git</code> directory. For bare repositories, repository is * the parent of the <code>objects</code> directory. * * @param repository {@link java.io.File} of the git repository * @return a {@link org.jenkinsci.plugins.gitclient.Git} object for repository access */ public Git in(File repository) { return in(new FilePath(repository)); }
/** * 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 protected void perform(final TaskListener listener) throws Exception { final EnvVars environment = getRun().getEnvironment(listener); final FilePath workspace = new FilePath(new File(ws)); final GitClient git = Git.with(listener, environment) .in(workspace) .getClient(); for (Map.Entry<String, String> entry : tagSet.entrySet()) { try { String buildNum = "jenkins-" + getRun().getParent().getName().replace(" ", "_") + "-" + entry.getValue(); git.tag(entry.getValue(), "Jenkins Build #" + buildNum); for (Map.Entry<String, String> e : tagSet.entrySet()) GitTagAction.this.tags.get(e.getKey()).add(e.getValue()); getRun().save(); workerThread = null; } catch (GitException ex) { ex.printStackTrace(listener.error("Error tagging repo '%s' : %s", entry.getKey(), ex.getMessage())); // Failed. Try the next one listener.getLogger().println("Trying next branch"); } } } }
public GitConfig getGitConfig() throws AbortException { try { GitClient client = Git.with(listener, env).in(workspace).getClient(); return client.withRepository(new GitInfoCallback(listener)); } catch (Exception e) { throw new AbortException("Error getting git config " + e); } }
public GitConfig getGitConfig() throws AbortException { try { GitClient client = Git.with(listener, env).in(workspace).getClient(); return client.withRepository(new GitInfoCallback(listener)); } catch (Exception e) { throw new AbortException("Error getting git config " + e); } }
@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; } }
try { File cacheDir = getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = resolveGitTool(context.gitTool()); if (tool != null) {
try { File cacheDir = AbstractGitSCMSource.getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = gitSCM.resolveGitTool(listener); if (tool != null) {
try { File cacheDir = AbstractGitSCMSource.getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = gitSCMSource.resolveGitTool(builder.gitTool()); if (tool != null) {
@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; }