Skip to content
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
3 changes: 1 addition & 2 deletions cli/src/main/java/hudson/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public static int _main(String[] _args) throws Exception {

boolean noKeyAuth = false;

// TODO perhaps allow mode to be defined by environment variable too (assuming $JENKINS_USER_ID can be used for -user)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4369 (comment)

If anything we could introduce something like

export JENKINS_CLI_OPTS="-http -s https://jenkins/ -auth admin:$(cat token)"

Mode mode = null;

String user = null;
Expand Down Expand Up @@ -273,7 +272,7 @@ public boolean verify(String s, SSLSession sslSession) {
args = List.of("help"); // default to help

if (mode == null) {
mode = Mode.HTTP;
mode = Mode.WEB_SOCKET;
}

LOGGER.log(FINE, "using connection mode {0}", mode);
Expand Down
10 changes: 5 additions & 5 deletions cli/src/main/resources/hudson/cli/client/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ CLI.Usage=Jenkins CLI\n\
Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...\n\
Options:\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 : like -http but using WebSocket (works better with most reverse proxies)\n\
\ -ssh : use SSH protocol (requires -user; SSH port must be open on server, and user must have registered a public key)\n\
\ -webSocket : connect using WebSocket (the default; works well with most reverse proxies; requires Jetty)\n\
\ -http : use a pair of HTTP(S) connections rather than WebSocket\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\
\ -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\
\ -user : specify user (for use with -ssh)\n\
\ -noKeyAuth : do not try to load the SSH authentication private key. Conflicts with -i\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\
\ -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\
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/cli/CLIAction/example.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ THE SOFTWARE.

<?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">
<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>

4 changes: 1 addition & 3 deletions test/src/test/java/hudson/cli/CLIActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void authentication() throws Exception {
private static final String ADMIN = "admin@mycorp.com";

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) {
commands.add("-auth");
commands.add(ADMIN + ":" + User.getOrCreateByIdOrFullName(ADMIN).getProperty(ApiTokenProperty.class).getApiToken());
Expand Down Expand Up @@ -140,7 +140,6 @@ public void encodingAndLocale() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
assertEquals(0, new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds(
"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").
stdout(baos).stderr(System.err).join());
assertEquals("encoding=ISO-8859-2 locale=cs_CZ", baos.toString(Charset.forName("ISO-8859-2")).trim());
Expand All @@ -160,7 +159,6 @@ public void interleavedStdio() throws Exception {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new TeeOutputStream(pos, System.err), Charset.defaultCharset()), true);
Proc proc = new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds(
"java", "-jar", jar.getAbsolutePath(), "-s", j.getURL().toString(),
"-webSocket", // TODO as above
"groovysh").
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)
Expand Down