未验证 提交 3ca28803 编写于 作者: J Jesse Glick 提交者: GitHub

Default CLI mode to `-webSocket` (#7605)

* Default CLI mode to `-webSocket`

* Recommend `-http` only if needed

* Simplifying `CLIActionTest`

* Avoid an extra space in proposed command if not using `-http`
上级 c3f91617
...@@ -124,7 +124,6 @@ public class CLI { ...@@ -124,7 +124,6 @@ public class CLI {
boolean noKeyAuth = false; boolean noKeyAuth = false;
// TODO perhaps allow mode to be defined by environment variable too (assuming $JENKINS_USER_ID can be used for -user)
Mode mode = null; Mode mode = null;
String user = null; String user = null;
...@@ -273,7 +272,7 @@ public class CLI { ...@@ -273,7 +272,7 @@ public class CLI {
args = List.of("help"); // default to help args = List.of("help"); // default to help
if (mode == null) { if (mode == null) {
mode = Mode.HTTP; mode = Mode.WEB_SOCKET;
} }
LOGGER.log(FINE, "using connection mode {0}", mode); LOGGER.log(FINE, "using connection mode {0}", mode);
......
...@@ -2,13 +2,13 @@ CLI.Usage=Jenkins CLI\n\ ...@@ -2,13 +2,13 @@ CLI.Usage=Jenkins CLI\n\
Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...\n\ Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...\n\
Options:\n\ Options:\n\
\ -s URL : the server URL (defaults to the JENKINS_URL env var)\n\ \ -s URL : the server URL (defaults to the JENKINS_URL env var)\n\
\ -http : use a plain CLI protocol over HTTP(S) (the default; mutually exclusive with -ssh)\n\ \ -webSocket : connect using WebSocket (the default; works well with most reverse proxies; requires Jetty)\n\
\ -webSocket : like -http but using WebSocket (works better with most reverse proxies)\n\ \ -http : use a pair of HTTP(S) connections rather than WebSocket\n\
\ -ssh : use SSH protocol (requires -user; SSH port must be open on server, and user must have registered a public key)\n\ \ -ssh : use SSH protocol rather than WebSocket (requires -user; SSH port must be open on server)\n\
\ -i KEY : SSH private key file used for authentication (for use with -ssh)\n\ \ -i KEY : SSH private key file used for authentication (for use with -ssh)\n\
\ -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution\n\ \ -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution\n\
\ -noKeyAuth : don''t try to load the SSH authentication private key. Conflicts with -i\n\ \ -noKeyAuth : do not try to load the SSH authentication private key. Conflicts with -i\n\
\ -user : specify user (for use with -ssh)\n\ \ -user : specify user (for use with -ssh; must have registered a public key)\n\
\ -strictHostKey : request strict host key checking (for use with -ssh)\n\ \ -strictHostKey : request strict host key checking (for use with -ssh)\n\
\ -logger FINE : enable detailed logging from the client\n\ \ -logger FINE : enable detailed logging from the client\n\
\ -auth [ USER:SECRET | @FILE ] : specify username and either password or API token (or load from them both from a file);\n\ \ -auth [ USER:SECRET | @FILE ] : specify username and either password or API token (or load from them both from a file);\n\
......
...@@ -24,6 +24,6 @@ THE SOFTWARE. ...@@ -24,6 +24,6 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<pre id="example">java -jar <a href="${rootURL}/jnlpJars/jenkins-cli.jar">jenkins-cli.jar</a> -s ${h.inferHudsonURL(request)} <j:if test="${it.webSocketSupported}">-webSocket</j:if> ${commandArgs}</pre> <pre id="example">java -jar <a href="${rootURL}/jnlpJars/jenkins-cli.jar">jenkins-cli.jar</a> -s ${h.inferHudsonURL(request)} <j:if test="${!it.webSocketSupported}">-http </j:if>${commandArgs}</pre>
</j:jelly> </j:jelly>
...@@ -104,7 +104,7 @@ public class CLIActionTest { ...@@ -104,7 +104,7 @@ public class CLIActionTest {
private static final String ADMIN = "admin@mycorp.com"; private static final String ADMIN = "admin@mycorp.com";
private void assertExitCode(int code, boolean useApiToken, File jar, String... args) throws IOException, InterruptedException { private void assertExitCode(int code, boolean useApiToken, File jar, String... args) throws IOException, InterruptedException {
List<String> commands = new ArrayList<>(Arrays.asList("java", "-jar", jar.getAbsolutePath(), "-s", j.getURL().toString(), /* TODO until it is the default */ "-webSocket")); List<String> commands = new ArrayList<>(Arrays.asList("java", "-jar", jar.getAbsolutePath(), "-s", j.getURL().toString()));
if (useApiToken) { if (useApiToken) {
commands.add("-auth"); commands.add("-auth");
commands.add(ADMIN + ":" + User.getOrCreateByIdOrFullName(ADMIN).getProperty(ApiTokenProperty.class).getApiToken()); commands.add(ADMIN + ":" + User.getOrCreateByIdOrFullName(ADMIN).getProperty(ApiTokenProperty.class).getApiToken());
...@@ -140,7 +140,6 @@ public class CLIActionTest { ...@@ -140,7 +140,6 @@ public class CLIActionTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
assertEquals(0, new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds( assertEquals(0, new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds(
"java", "-Dfile.encoding=ISO-8859-2", "-Duser.language=cs", "-Duser.country=CZ", "-jar", jar.getAbsolutePath(), "java", "-Dfile.encoding=ISO-8859-2", "-Duser.language=cs", "-Duser.country=CZ", "-jar", jar.getAbsolutePath(),
"-webSocket", // TODO as above
"-s", j.getURL().toString()./* just checking */replaceFirst("/$", ""), "test-diagnostic"). "-s", j.getURL().toString()./* just checking */replaceFirst("/$", ""), "test-diagnostic").
stdout(baos).stderr(System.err).join()); stdout(baos).stderr(System.err).join());
assertEquals("encoding=ISO-8859-2 locale=cs_CZ", baos.toString(Charset.forName("ISO-8859-2")).trim()); assertEquals("encoding=ISO-8859-2 locale=cs_CZ", baos.toString(Charset.forName("ISO-8859-2")).trim());
...@@ -160,7 +159,6 @@ public class CLIActionTest { ...@@ -160,7 +159,6 @@ public class CLIActionTest {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new TeeOutputStream(pos, System.err), Charset.defaultCharset()), true); PrintWriter pw = new PrintWriter(new OutputStreamWriter(new TeeOutputStream(pos, System.err), Charset.defaultCharset()), true);
Proc proc = new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds( Proc proc = new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds(
"java", "-jar", jar.getAbsolutePath(), "-s", j.getURL().toString(), "java", "-jar", jar.getAbsolutePath(), "-s", j.getURL().toString(),
"-webSocket", // TODO as above
"groovysh"). "groovysh").
stdout(new TeeOutputStream(baos, System.out)).stderr(System.err).stdin(pis).start(); stdout(new TeeOutputStream(baos, System.out)).stderr(System.err).stdin(pis).start();
while (!baos.toString(Charset.defaultCharset()).contains("000")) { // cannot just search for, say, "groovy:000> " since there are ANSI escapes there (cf. StringEscapeUtils.escapeJava) while (!baos.toString(Charset.defaultCharset()).contains("000")) { // cannot just search for, say, "groovy:000> " since there are ANSI escapes there (cf. StringEscapeUtils.escapeJava)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册