/** * 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(); }
/** * Fluent constructor for a Git object. Either * <code>Git.with(listener, env)</code> or new * <code>Git(listener, env)</code> can be used to construct a Git object. * * @param listener a {@link hudson.model.TaskListener} which can be used to * monitor git implementation operations * @param env a {@link hudson.EnvVars} which provides environment values to * the git implementation * @return a {@link org.jenkinsci.plugins.gitclient.Git} object for repository access */ public static Git with(TaskListener listener, EnvVars env) { return new Git(listener, env); }
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; }
/** * 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)); }
@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; } }
@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"); } } } }
try { File cacheDir = getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = resolveGitTool(context.gitTool()); if (tool != null) { git.using(tool.getGitExe()); GitClient client = git.getClient(); client.addDefaultCredentials(getCredentials()); if (!client.hasGitRepo()) {
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) { git.using(tool.getGitExe()); GitClient client = git.getClient(); client.addDefaultCredentials(gitSCMSource.getCredentials()); if (!client.hasGitRepo()) {
@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; }
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) { git.using(tool.getGitExe()); GitClient client = git.getClient(); String credentialsId = config.getCredentialsId(); if (credentialsId != null) {