private String retrieveRevisionToBuild(PushHook hook, GitSCM gitSCM) throws NoRevisionToBuildException { if (inNoBranchDelete(hook)) { if (gitSCM != null && gitSCM.getRepositories().size() == 1) { String repositoryName = gitSCM.getRepositories().get(0).getName(); return hook.getRef().replaceFirst("^refs/heads", "remotes/" + repositoryName); } else { return hook.getAfter(); } } else { throw new NoRevisionToBuildException(); } }
/** * Get the URL of the first declared repository in the project configuration. * Use this as default source repository url. * * @return URIish the default value of the source repository url * @throws IllegalStateException Project does not use git scm. */ private URIish getSourceRepoURLDefault(Job<?, ?> job) { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); GitSCM gitSCM = getGitSCM(item); if (gitSCM == null) { LOGGER.log(Level.WARNING, "Could not find GitSCM for project. Project = {1}, next build = {2}", array(job.getName(), String.valueOf(job.getNextBuildNumber()))); throw new IllegalStateException("This project does not use git:" + job.getName()); } return getFirstRepoURL(gitSCM.getRepositories()); }
/** * Get the URL of the first declared repository in the project configuration. * Use this as default source repository url. * * @return URIish the default value of the source repository url * @throws IllegalStateException Project does not use git scm. */ private URIish getSourceRepoURLDefault(Job<?, ?> job) { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); GitSCM gitSCM = getGitSCM(item); if (gitSCM == null) { LOGGER.log(Level.WARNING, "Could not find GitSCM for project. Project = {1}, next build = {2}", array(job.getName(), String.valueOf(job.getNextBuildNumber()))); throw new IllegalStateException("This project does not use git:" + job.getName()); } return getFirstRepoURL(gitSCM.getRepositories()); }
public RemoteConfig getRepositoryByName(String repoName) { for (RemoteConfig r : getRepositories()) { if (r.getName().equals(repoName)) { return r; } } return null; }
public RemoteConfig getRepositoryByName(String repoName) { for (RemoteConfig r : getRepositories()) { if (r.getName().equals(repoName)) { return r; } } return null; }
public RemoteConfig getRepositoryByName(String repoName) { for (RemoteConfig r : getRepositories()) { if (r.getName().equals(repoName)) { return r; } } return null; }
@Override public String getKey() { String name = getScmName(); if (name != null) { return name; } StringBuilder b = new StringBuilder("git"); for (RemoteConfig cfg : getRepositories()) { for (URIish uri : cfg.getURIs()) { b.append(' ').append(uri.toString()); } } return b.toString(); }
/** * {@inheritDoc} */ @Override public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, CloneCommand cmd) throws IOException, InterruptedException, GitException { listener.getLogger() .printf("Cloning with configured refspecs honoured and %s tags%n", includeTags ? "with" : "without"); RemoteConfig rc = scm.getRepositories().get(0); List<RefSpec> refspecs = rc.getFetchRefSpecs(); cmd.refspecs(refspecs); cmd.tags(includeTags); }
public String getRemoteUrl(String defaultRemoteUrl) { if (StringUtils.isBlank(defaultRemoteUrl)) { RemoteConfig remoteConfig = getJenkinsScm().getRepositories().get(0); URIish uri = remoteConfig.getURIs().get(0); return uri.toPrivateString(); } return defaultRemoteUrl; }
private URL getUrlFromFirstConfiguredRepository(GitChangeSet changeSet) throws MalformedURLException { GitSCM scm = getScmFromProject(changeSet); return new URL(scm.getRepositories().get(0).getURIs().get(0).toString()); }
public Map<String, URIish> getCommitRepoMap() throws Exception { List<RemoteConfig> repoList = this.gitScm.getRepositories(); if (repoList.size() != 1) { throw new Exception("None or multiple repos"); } HashMap<String, URIish> commitRepoMap = new HashMap<String, URIish>(); BuildData buildData = build.getAction(BuildData.class); if (buildData == null || buildData.getLastBuiltRevision() == null) { logger.warning("Build data could not be found"); } else { commitRepoMap.put(buildData.getLastBuiltRevision().getSha1String(), repoList.get(0).getURIs().get(0)); } return commitRepoMap; } }
public String getBranchNameWithoutRemote(String branchName) { List<RemoteConfig> repositories = getJenkinsScm().getRepositories(); for (RemoteConfig remoteConfig : repositories) { String prefix = remoteConfig.getName() + "/"; if (branchName.startsWith(prefix)) { return StringUtils.removeStart(branchName, prefix); } } return branchName; }
/** * If the configuration is such that we are tracking just one branch of one repository * return that branch specifier (in the form of something like "origin/master" * <p/> * Otherwise return null. */ private String getSingleBranch(AbstractBuild<?, ?> build) { // if we have multiple branches skip to advanced usecase if (getBranches().size() != 1 || getRepositories().size() != 1) { return null; } String branch = getBranches().get(0).getName(); String repository = getRepositories().get(0).getName(); // replace repository wildcard with repository name if (branch.startsWith("*/")) { branch = repository + branch.substring(1); } // if the branch name contains more wildcards then the simple usecase // does not apply and we need to skip to the advanced usecase if (branch.contains("*")) { return null; } // substitute build parameters if available ParametersAction parameters = build.getAction(ParametersAction.class); if (parameters != null) { branch = parameters.substitute(build, branch); } return branch; }
protected static void addRepositories(SCM scm, EnvVars env, Collection<GitHubRepositoryName> r) { if (scm instanceof GitSCM) { GitSCM git = (GitSCM) scm; for (RemoteConfig rc : git.getRepositories()) { for (URIish uri : rc.getURIs()) { String url = env.expand(uri.toString()); GitHubRepositoryName repo = GitHubRepositoryName.create(url); if (repo != null) { r.add(repo); } } } } } }
public ReleaseRepository getRemoteConfig(String defaultRemoteNameOrUrl) throws IOException { List<RemoteConfig> repositories = getJenkinsScm().getRepositories(); if (StringUtils.isBlank(defaultRemoteNameOrUrl)) { if (repositories == null || repositories.isEmpty()) { throw new GitException("Git remote config repositories are null or empty."); } return new ReleaseRepository(repositories.get(0).getURIs().get(0), repositories.get(0).getName()); } for (RemoteConfig remoteConfig : repositories) { if (remoteConfig.getName().equals(defaultRemoteNameOrUrl)) { return new ReleaseRepository(remoteConfig.getURIs().get(0), remoteConfig.getName()); } } if (checkGitValidUri(defaultRemoteNameOrUrl)) { return new ReleaseRepository(defaultRemoteNameOrUrl, "externalGitUrl"); } throw new IOException("Target Remote Name: " + defaultRemoteNameOrUrl + " ,doesn`t exist"); }
RemoteConfig rc = scm.getRepositories().get(0); List<RefSpec> refspecs = rc.getFetchRefSpecs(); cmd.refspecs(refspecs);
private void addRemoteRepoToConfig(GitClient client) throws InterruptedException { GitSCM gitScm = getJenkinsScm(); for (RemoteConfig uc : gitScm.getRepositories()) { if (client.getRemoteUrl(uc.getName()) == null) client.setRemoteUrl(uc.getName(), uc.getURIs().get(0).toPrivateASCIIString()); } }
private boolean match(SCM scm, URIish url) { if (scm instanceof GitSCM) { for (RemoteConfig remoteConfig : ((GitSCM) scm).getRepositories()) { for (URIish urIish : remoteConfig.getURIs()) { // needed cause the ssh and https URI differs in Bitbucket Server. if(urIish.getPath().startsWith("/scm")){ urIish = urIish.setPath(urIish.getPath().substring(4)); } LOGGER.log(Level.FINE, "Trying to match {0} ", urIish.toString() + "<-->" + url.toString()); if (GitStatus.looselyMatches(urIish, url)) { return true; } } } } else if (scm instanceof MercurialSCM) { try { URI hgUri = new URI(((MercurialSCM) scm).getSource()); String remote = url.toString(); if (looselyMatches(hgUri, remote)) { return true; } } catch (URISyntaxException ex) { LOGGER.log(Level.SEVERE, "Could not parse jobSource uri: {0} ", ex); } } return false; }
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) { super.buildEnvVars(build, env); GitUtils.buildBranchEnvVar(build, env, getRepositories(), getBranches()); BuildData bd = fixNull(getBuildData(build, false)); if (bd != null && bd.getLastBuiltRevision() != null) { String commit = bd.getLastBuiltRevision().getSha1String(); if (commit != null) { env.put(GIT_COMMIT, commit); } } }
return false; for (RemoteConfig repository : git.getRepositories()) { for (URIish remoteURL : repository.getURIs()) { if (GitStatus.looselyMatches(uri, remoteURL)) {