Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-46094] Fix SSH Clone trait using agent credentials #205

Merged
merged 4 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public class GitHubSCMBuilder extends GitSCMBuilder<GitHubSCMBuilder> {
/**
* Singleton instance of {@link HttpsRepositoryUriResolver}.
*/
private static final HttpsRepositoryUriResolver HTTPS = new HttpsRepositoryUriResolver();
static final HttpsRepositoryUriResolver HTTPS = new HttpsRepositoryUriResolver();
/**
* Singleton instance of {@link SshRepositoryUriResolver}.
*/
private static final SshRepositoryUriResolver SSH = new SshRepositoryUriResolver();
static final SshRepositoryUriResolver SSH = new SshRepositoryUriResolver();
/**
* The GitHub API suffix for GitHub Server.
*/
Expand Down Expand Up @@ -96,6 +96,11 @@ public class GitHubSCMBuilder extends GitSCMBuilder<GitHubSCMBuilder> {
*/
@CheckForNull
private final URL repositoryUrl;
/**
* The repository name.
*/
@NonNull
private RepositoryUriResolver uriResolver = GitHubSCMBuilder.HTTPS;

/**
* Constructor.
Expand Down Expand Up @@ -131,6 +136,7 @@ public GitHubSCMBuilder(@NonNull GitHubSCMSource source,
if (repoUrl != null) {
withBrowser(new GithubWeb(repoUrl));
}
withCredentials(credentialsId(), null);
}

/**
Expand Down Expand Up @@ -181,8 +187,29 @@ public final String repositoryUrl(String owner, String repo) {
*/
@NonNull
public final RepositoryUriResolver uriResolver() {
String credentialsId = credentialsId();
return uriResolver(context, apiUri, credentialsId);
return uriResolver;
}

/**
* Configures the {@link IdCredentials#getId()} of the {@link Credentials} to use when connecting to the
* {@link #remote()}
*
* @param credentialsId the {@link IdCredentials#getId()} of the {@link Credentials} to use when connecting to
* the {@link #remote()} or {@code null} to let the git client choose between providing its own
* credentials or connecting anonymously.
* @param uriResolver the {@link RepositoryUriResolver} of the {@link Credentials} to use or {@code null}
* to detect the the protocol based on the credentialsId. Defaults to HTTP if credentials are
* {@code null}. Enables support for blank SSH credentials.
* @return {@code this} for method chaining.
*/
@NonNull
public GitHubSCMBuilder withCredentials(String credentialsId, RepositoryUriResolver uriResolver) {
if (uriResolver == null) {
uriResolver = uriResolver(context, apiUri, credentialsId);
}

this.uriResolver = uriResolver;
return withCredentials(credentialsId);
}

/**
Expand All @@ -193,6 +220,7 @@ public final RepositoryUriResolver uriResolver() {
* @param credentialsId the credentials.
* @return a {@link RepositoryUriResolver}
*/
@NonNull
public static RepositoryUriResolver uriResolver(@CheckForNull Item context, @NonNull String apiUri,
@CheckForNull String credentialsId) {
if (credentialsId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public final String getCredentialsId() {
*/
@Override
protected void decorateBuilder(SCMBuilder<?,?> builder) {
((GitSCMBuilder<?>)builder).withCredentials(credentialsId);
((GitHubSCMBuilder)builder).withCredentials(credentialsId, GitHubSCMBuilder.SSH);
}

/**
Expand Down
Loading