Skip to content
Open
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
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.framework.io.WriterOutputStream;

Expand Down Expand Up @@ -2150,6 +2151,15 @@ private String launchCommandWithCredentials(
env = new EnvVars(env);
env.put("GIT_ASKPASS", askpass.toAbsolutePath().toString());
env.put("SSH_ASKPASS", askpass.toAbsolutePath().toString());

} else if (credentials instanceof StringCredentials) {
var stringCred = (StringCredentials) credentials;
listener.getLogger().println("using GIT_CONFIG to set token header " + stringCred.getDescription());

env = new EnvVars(env);
env.put("GIT_CONFIG_COUNT", "1");
env.put("GIT_CONFIG_KEY_0", "http.extraHeader");
env.put("GIT_CONFIG_VALUE_0", "Authorization: Bearer " + stringCred.getSecret());
}

if ("http".equalsIgnoreCase(url.getScheme()) || "https".equalsIgnoreCase(url.getScheme())) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jenkinsci/plugins/gitclient/GitClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;

/**
* Interface to Git functionality.
Expand All @@ -47,7 +48,8 @@ public interface GitClient {
*/
CredentialsMatcher CREDENTIALS_MATCHER = CredentialsMatchers.anyOf(
CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
CredentialsMatchers.instanceOf(SSHUserPrivateKey.class));
CredentialsMatchers.instanceOf(SSHUserPrivateKey.class),
CredentialsMatchers.instanceOf(StringCredentials.class));

/**
* Remove all credentials from the client.
Expand Down