Skip to content

Commit

Permalink
Allow exposing HTTP and Agent connection ports via --httpPort and `…
Browse files Browse the repository at this point in the history
…--agentPort` options
  • Loading branch information
oleg-nenashev committed Jun 7, 2021
1 parent 4a447e9 commit edd0825
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ Advanced arguments:
Also, plugin https://javadoc.jenkins.io/hudson/init/Terminator.html[@Terminator] extensions will not be invoked.
It may lead to undefined behavior in the system, including potential data loss.
This option is considered safe for the Vanilla package with the default plugin set.
* `--httpPort` - Port for exposing the web server and Jenkins Web UI from Jenkinsfile Runner.
Disabled by default.
* `--agentPort` - Port for connecting inbound Jenkins agents (over JNLP or WebSockets).
Disabled by default.


==== Running Jenkinsfiles (`run` command)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.jenkins.jenkinsfile.runner.bootstrap.commands;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import picocli.CommandLine;

import java.io.File;
Expand Down Expand Up @@ -62,7 +63,16 @@ public class JenkinsLauncherOptions {
description = "When a slim packaging is used, points to the library directory which contains payload.jar and setup.jar files")
public File libPath;

@CheckForNull
@CommandLine.Option(names = "--httpPort",
description = "Port for exposing the web server and Jenkins Web UI from Jenkinsfile Runner. Disabled by default")
public Integer httpPort;

@CheckForNull
@CommandLine.Option(names = "--agentPort",
description = "Port for connecting inbound Jenkins agents (over JNLP or WebSockets). Disabled by default")
public Integer agentPort;

public String getMirrorURL(String url) {
if (this.mirror == null || "".equals(this.mirror.trim())) {
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ protected Jenkins newJenkins() throws Exception {
final Jenkins j = super.newJenkins();
// Notify the bootstrap about the plugin classloader to be used in its logic
// command.setPluginClassloader(j.getPluginManager().uberClassLoader);

// Configure the agent endpoint
if (command.launcherOptions.agentPort != null) {
j.setSlaveAgentPort(command.launcherOptions.agentPort);
}

return j;
}

Expand All @@ -67,7 +73,9 @@ protected ServletContext createWebServer() throws Exception {
final JenkinsLauncherOptions launcherOptions = command.getLauncherOptions();

QueuedThreadPool queuedThreadPool = new QueuedThreadPool(10);
server = new Server(queuedThreadPool);
server = launcherOptions.httpPort != null
? new Server(launcherOptions.httpPort)
: new Server(queuedThreadPool);

WebAppContext context = new WebAppContext(launcherOptions.warDir.getPath(), contextPath);
context.setClassLoader(getClass().getClassLoader());
Expand All @@ -84,7 +92,7 @@ protected ServletContext createWebServer() throws Exception {

server.start();

localPort = -1;
localPort = launcherOptions.httpPort != null ? launcherOptions.httpPort : -1;

String pluginManagerClass = SystemProperties.getString(PluginManager.CUSTOM_PLUGIN_MANAGER);
if (pluginManagerClass == null) {
Expand Down

0 comments on commit edd0825

Please sign in to comment.