Skip to content

Add configurable SSH port for agent connections#545

Open
ToshipSo wants to merge 2 commits intojenkinsci:developfrom
ToshipSo:feature/configurable-ssh-port
Open

Add configurable SSH port for agent connections#545
ToshipSo wants to merge 2 commits intojenkinsci:developfrom
ToshipSo:feature/configurable-ssh-port

Conversation

@ToshipSo
Copy link
Copy Markdown

@ToshipSo ToshipSo commented Apr 25, 2026

Summary

  • Adds a configurable SSH port field to Instance Configuration (defaults to 22)
  • Removes the hardcoded SSH_PORT = 22 constant from ComputeEngineComputerLauncher
  • Includes UI field, form validation (1-65535), inline help, and backward compatibility for existing serialized configs

Resolves #134

Changes

  • InstanceConfiguration - new sshPort field with @DataBoundSetter, descriptor validation (1-65535), builder support
  • ComputeEngineInstance - stores sshPort with backward-compatible getter for older serialized configs
  • ComputeEngineComputerLauncher - uses node.getSshPort() instead of hardcoded SSH_PORT constant
  • config.jelly - SSH Port number field in Launch Configuration section
  • help-sshPort.html - inline help

Testing done

Automated Tests

Six tests in InstanceConfigurationTest cover the new SSH port logic:

Test What it verifies
testSshPortDefaultValue setSshPort(null) falls back to default port 22
testSshPortCustomValue setSshPort(2222) stores and returns 2222
testSshPortInvalidValuesFallBackToDefault Out-of-range values (0, -1, 70000) all fall back to 22
testSshPortBoundaryValues Boundary ports 1 and 65535 are accepted
descriptorSshPortValidation Form validation accepts valid ports (1, 22, 2222, 65535), rejects invalid input (0, -1, 65536, "abc"), and permits empty/null
testConfigRoundtrip Updated to include sshPort — verifies the field survives a Jenkins save/load cycle through the UI form
All tests pass via mvn test -Dtest=InstanceConfigurationTest.

Manual Testing

Launched Jenkins locally with mvn hpi:run and verified:

  1. UI field present: The "SSH Port" field appears in the Launch Configuration section with a default value of 22
  2. Inline help: The (?) icon next to the field displays the help text
  3. Validation feedback: Entering invalid values (0, 70000, "abc") shows an error; valid ports (22, 2222, 443) show no error
image image
  1. Persistence: Set port to 2222, saved config, reopened — value persisted correctly
image
  1. Default behavior: Left the field at 22 (default), saved — behaves identically to previous plugin behavior

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Previously the SSH port was hardcoded to 22 in ComputeEngineComputerLauncher.
This adds a user-configurable SSH port field to the instance configuration,
defaulting to 22 for backward compatibility.
Resolves google-compute-engine-plugin/issues/134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuration of SSH port and timeout for ComputeEngineComputerLauncher

2 participants