mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-05 16:15:54 +00:00
[JENKINS-53792] Env vars to configure CLI -auth option (#3653)
* [JENKINS-53792] Add env vars for auth option * [JENKINS-53792] Fix encoding after first commit * [JENKINS-53792] Better readability * [JENKINS-53792] Refactor and use the ApiToken * [JENKINS-53792] Fix encoding
This commit is contained in:
1 parent
e0ed9a86e0
commit
e998a7808f
7 files changed
+292
-9
No files matched your search
@@ -77,6 +77,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import static java.util.logging.Level.*;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* CLI entry point to Jenkins.
|
||||
@@ -452,6 +453,10 @@ public class CLI implements AutoCloseable {
|
||||
|
||||
String user = null;
|
||||
String auth = null;
|
||||
|
||||
String userIdEnv = System.getenv("JENKINS_USER_ID");
|
||||
String tokenEnv = System.getenv("JENKINS_API_TOKEN");
|
||||
|
||||
boolean strictHostKey = false;
|
||||
|
||||
while(!args.isEmpty()) {
|
||||
@@ -563,6 +568,17 @@ public class CLI implements AutoCloseable {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (auth == null) {
|
||||
// -auth option not set
|
||||
if (StringUtils.isNotBlank(userIdEnv) && StringUtils.isNotBlank(tokenEnv)) {
|
||||
auth = StringUtils.defaultString(userIdEnv).concat(":").concat(StringUtils.defaultString(tokenEnv));
|
||||
} else if (StringUtils.isNotBlank(userIdEnv) || StringUtils.isNotBlank(tokenEnv)) {
|
||||
printUsage(Messages.CLI_BadAuth());
|
||||
return -1;
|
||||
} // Otherwise, none credentials were set
|
||||
|
||||
}
|
||||
|
||||
if (!url.endsWith("/")) {
|
||||
url += '/';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user