How do I use SVN+SSH with a custom port and externals on Jenkins

We use SVN with SSH because it is better than anonymous access and the HTTP setup looked complicated and difficult to use when I was setting up authenticated SVN.

Subversion uses a custom port because it is running in a docker image and we use the default SSH port for SSH access to the host.

We use the .ssh/config file to automatically select the correct port.

As a result, all our SVN externals do not specify the port number. Maybe they should. I don’t know, but it will be a huge amount of work to change them.

The result is that when I configure a job, which has externals because they all do, I can specify a port number in the top level SVN URL, but that doesn’t help me because checking out all the externals fails.

I tried setting the SVN_SSH environment variable, but maybe I need to reload Jenkins or something because it doesn’t seem to help at all.

If I create /home/jenkins/.ssh/config on the docker image, will that solve the problem? Will the Jenkins Subversion plugin pick it up? Or does it need to be in /var/lib/jenkins/.ssh/config?

Hello @AlastairGrowcott and welcome to this community :wave:

If you create the .ssh/config file on the Docker image, it will not solve the problem, as Jenkins runs as a separate process and has its own home directory.

The Jenkins Subversion plugin uses the .subversion/config file in the home directory of the Jenkins user to read the SSH configuration. You can try adding the necessary configuration to this file by following these steps:

  1. Connect to the Jenkins server using SSH or any other method that allows you to access the file system.
  2. Navigate to the home directory of the Jenkins user, which is typically /var/lib/jenkins.
  3. Create the .subversion directory if it does not exist: mkdir ~/.subversion.
  4. Create the config file in the .subversion directory: touch ~/.subversion/config.
  5. Open the config file in a text editor and add the necessary SSH configuration, such as:
ssh = ssh -p 2222

Replace 2222 with the custom port number that you are using for SSH.

  1. Save the file and exit the text editor.

After adding the SSH configuration to the config file, you may need to restart the Jenkins service for the changes to take effect. Once the changes are in effect, the Jenkins Subversion plugin should be able to read the SSH configuration from the config file and use the correct port number when checking out the externals.

Thank you so much.

I will try it as soon as possible.

That didn’t work.

When explicitly setting the port number in the main URL, I get:

`Started by user Alastair Growcott
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/Firmware/AzipodDriver
Checking out a fresh workspace because there’s no workspace at /var/lib/jenkins/workspace/Firmware/AzipodDriver
Cleaning local Directory . Checking out svn+ssh://subversion.dynautics.local:2223/storage/repo/trunk/Firmware/AzipodDriver at revision ‘2023-03-06T10:53:50.660 +0000’ --quiet
Using sole credentials jenkins (Subversion) in realm ?svn+ssh://subversion.dynautics.local:2223?
Using sole credentials jenkins (Subversion) in realm ?svn+ssh://subversion.dynautics.local:2223?
Using sole credentials jenkins (Subversion) in realm ?svn+ssh://subversion.dynautics.local?

← Got one external: DriverLib, svn url: svn+ssh://subversion.dynautics.local/storage/repo/trunk/Firmware/DriverLib →
Using sole credentials jenkins (Subversion) in realm ?svn+ssh://subversion.dynautics.local?
Fetching ‘svn+ssh://subversion.dynautics.local/storage/repo/trunk/Firmware/DriverLib’ at -1 into ‘/var/lib/jenkins/workspace/Firmware/AzipodDriver/DriverLib’ failed!
ERROR: Failed to check out svn+ssh://subversion.dynautics.local:2223/storage/repo/trunk/Firmware/AzipodDriver`

Which is followed by a load of Java error reporting, which is followed by yet more Java error reporting as the email plugin fails horribly too. On a side note I am using the extended email plugin or something which, unlike the ordinary one, has no option to send a test email :frowning:

If I remove the explicit port number in the URL, I get this:

Started by user Alastair Growcott Running as SYSTEM Building in workspace /var/lib/jenkins/workspace/Firmware/AzipodDriver Checking out a fresh workspace because the workspace is not svn+ssh://subversion.dynautics.local/storage/repo/trunk/Firmware/AzipodDriver Cleaning local Directory . Checking out svn+ssh://subversion.dynautics.local/storage/repo/trunk/Firmware/AzipodDriver at revision 2023-03-06T10:59:42.727 +0000' --quiet Using sole credentials jenkins (Subversion) in realm ?svn+ssh://subversion.dynautics.local? Using sole credentials jenkins (Subversion) in realm ?svn+ssh://subversion.dynautics.local? ERROR: Subversion checkout has been canceled Build was aborted Finished: ABORTED

Here is some console output from within the docker image:

`root@builder:/var/lib/jenkins# cat .subversion/config
ssh = ssh -p 2223

root@builder:/var/lib/jenkins# service jenkins start

  • Starting Jenkins Automation Server jenkins Correct java version found
    Setting up max open files limit to 8192
    [ OK ]`
1 Like

I posted a reply with lots of details. The spam filter hid it while I was trying to edit it to make it more readable. The “preformatted text” markers are a bit rubbish, so lines were being concatenated and not properly formatted, etc. etc.

1 Like

I have raised an issue in the Subversion plugin for this: [JENKINS-70762] Cannot specify default SSH port. - Jenkins Jira

I cannot find any documentation of any configuration files for the Subversion plugin.

1 Like

I think you did well in opening an issue. :+1:

If you need to specify a custom port for your Subversion repository in Jenkins, you could maybe do so by including the port number in the SVN URL. For example, if your repository is running on port 2222, you could specify the URL as svn+ssh://user@host:2222/path/to/repo.

If your externals do not specify the port number, you can specify the port number in the parent repository URL as described above, and the externals will inherit that port number.

Regarding the SVN_SSH environment variable, setting it to the path of your SSH binary should work to specify the path to the SSH binary used by the Subversion plugin. However, you may need to restart Jenkins for the change to take effect.