Pipeline fails sshagent (credentials:); SSH cert definitely works

I am trying to build a new Windows 11 build server, and wanted to transfer the pipelines from a working Win10 Jenkins build server to the new one.

This simple test pipeline

pipeline 
{
    agent any
    stages 
    {
        stage('Checkout') 
        {
            steps 
            { 
                sshagent (credentials: ['credentials_ID']) 
                {
                    deleteDir()
                    bat 'git clone git@github.com:UserName/RepoName.git .'
                }
            }
        }
    }
}

fails with

Started by user Administrator
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Users\Jenkins\AppData\Local\Jenkins\.jenkins\workspace\rapidBIM
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] sshagent
[ssh-agent] Using credentials credentials_ID (GitHub connection)
$ ssh-agent
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: ae1100b9-99c9-4869-82df-d35048539373
java.lang.StringIndexOutOfBoundsException: begin 13, end -1, length 0
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)

I have tested the SSH credential in a new project I created. I set up the Git repository, and selected from the Credentials dropdown. No error message was shown below the Repository URL field.

I checked that ssh -T git@github.com worked, as did git ls-remote -h – git@github.com:repoName HEAD

As a new user I am not able to upload the full error message or my full setup.

Setup summary is:
Jenkins: 2.504.2
OS: Windows 11 - 10.0
Java: 17.0.14 - OpenLogic (OpenJDK 64-Bit Server VM)

More of error message log is:

Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: ae1100b9-99c9-4869-82df-d35048539373
java.lang.StringIndexOutOfBoundsException: begin 13, end -1, length 0
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
	at java.base/java.lang.String.substring(String.java:2709)
	at PluginClassLoader for ssh-agent//com.cloudbees.jenkins.plugins.sshagent.exec.ExecRemoteAgent.getAgentValue(ExecRemoteAgent.java:146)
	at PluginClassLoader for ssh-agent//com.cloudbees.jenkins.plugins.sshagent.exec.ExecRemoteAgent.parseAgentEnv(ExecRemoteAgent.java:130)
	at PluginClassLoader for ssh-agent//com.cloudbees.jenkins.plugins.sshagent.exec.ExecRemoteAgent.<init>(ExecRemoteAgent.java:57)
	at PluginClassLoader for ssh-agent//com.cloudbees.jenkins.plugins.sshagent.SSHAgentStepExecution.initRemoteAgent(SSHAgentStepExecution.java:121)
	at PluginClassLoader for ssh-agent//com.cloudbees.jenkins.plugins.sshagent.SSHAgentStepExecution.start(SSHAgentStepExecution.java:35)
	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:323)
	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at PluginClassLoader for script-security//org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:180)
	at PluginClassLoader for script-security//org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at PluginClassLoader for script-security//org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:163)
	at PluginClassLoader for script-security//org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:178)
	at PluginClassLoader for script-security//org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:182)
	at PluginClassLoader for script-security//org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
	at PluginClassLoader for workflow-cps//com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.LoggingInvoker.methodCall(LoggingInvoker.java:118)
	at WorkflowScript.run(WorkflowScript:21)
	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.delegateAndExecute(ModelInterpreter.groovy:139)

the ssh-agent from windows is not compatible with the sshagent step. The step expect that some env variables are printed to stdout which the windows version doesn’t do. You need to make sure that the ssh-agent from git is found in the path first, then it should work.

1 Like

Thank you very much for that; it turned out there were 5 other versions of ssh.exe on the system.

2 Likes