The Windows agent launched via SSH and on the agent we are having trouble executing SSH commands in a Jenkins pipeline.
Jenkins version: 2.452.1
Request you to help us to move forward.
The Windows agent launched via SSH and on the agent we are having trouble executing SSH commands in a Jenkins pipeline.
Jenkins version: 2.452.1
Request you to help us to move forward.
Could you share how you are invoking the ssh in the pipeline or if you are using any plugins.
Hi Markbosire,
Thanks for the reply. Here are the details.
Jenkins version: 2.462.3
SSH plugin version: 2.6.1
pipeline {
agent {
label âtemplate-2019â
}
stages {
stage(âSetupâ) {
steps {
dir (âtestâ) {
deleteDir()
}
}
}
stage(âBuildâ) {
steps {
sleep 3
bat(âsetâ)
}
}
stage(âTestâ) {
steps {
echo âTesting..â
sleep 3
bat âââset TERM=xterm
C:\Windows\System32\OpenSSH\ssh.exe -vvv -F /Users/jenkins/.ssh/config -i /Users/jenkins/.ssh/id_rsa -t -o StrictHostKeyChecking=no XXXX@XXXXXXXXXX ls -ltra >bla 2>&1âââ }
}
stage(âDeployâ) {
steps {
echo âDeployingâŚâ
}
}
}
}
Please find the attached output of ssh & pipeline
(Attachment pipeline.output.txt is missing)
(Attachment ssh.out.txt is missing)
Jenkins.zip (13.3 KB)
Please find the attachment.
The pipeline seems to be running in a mixed Windows/Unix environment. Your bat command is trying to use /Users/jenkins/.ssh/config which appears to be a Unix-style path, but youâre running on a Windows agent.
The agent is running on template-MG24 in the output but your pipeline specifies template-2019. This mismatch might indicate configuration issues.
Windows paths should use backslashes or escaped backslashes. For SSH config and key files, try:
bat âââset TERM=xterm
C:\Windows\System32\OpenSSH\ssh.exe -vvv -F C:\Users\jenkins\.ssh\config -i C:\Users\jenkins\.ssh\id_rsa -t -o StrictHostKeyChecking=no XXXX@XXXXXXXXXX ls -ltra >bla 2>&1âââ
Also Consider using the Jenkins SSH Steps plugin for cleaner syntax if available.
Also before executing complex commands, try a simple connection test:
bat âC:\Windows\System32\OpenSSH\ssh.exe -o StrictHostKeyChecking=no XXXX@XXXXXXXXXX echo Connection Successfulâ
Also check target server access: Ensure the target server allows SSH connections from your Jenkins agent and the user has appropriate permissions.
Hi Markbosire,
Since I was on vacation, I was not able to test and reply immediate.
Pipeline modified as below:
pipeline {
agent {
label âwindow-ssh-test-nodeâ
}
stages {
stage(âRun SSH Command on Windowsâ) {
steps {
bat âââ
C:\Windows\System32\OpenSSH\ssh.exe -vvv -F \users\jenkins\.ssh\config -I \Users\jenkins\.ssh\id_rsa -o StrictHostKeyChecking=no XXXXXXXXX@XXXXXXXXXXXXXXXXXX echo âConnection Successfulâ exit
âââ
}
}
}
}
Jenkins log:
Started by user Venkat
[Pipeline] Start of Pipeline
[Pipeline] node
Running on âwindow-ssh-test-nodeâ in /Users/jenkins/workspace/workspace/Ec2-Fleet/Ec2-Fleet-SSH
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Run SSH Command on Windows)
[Pipeline] bat
OpenSSH_for_Windows_8.6p1, LibreSSL 2.6.5
workspace\workspace\Ec2-Fleet\Ec2-Fleet-SSH>C:\Windows\System32\OpenSSH\ssh.exe -vvv -F \Users\jenkins.ssh\config -i \Users\jenkins.ssh\id_rsa -o StrictHostKeyChecking=no XXXXXXXXX@XXXXXXXXXXXXXXXXXX echo âConnection Successfulâ
post triggering the job, it is not completing (finally aborting the job). Not sure it connected to the target server and expecting inputs and hanging there.
Is your agent running on c-drive or another drive?
As you use
bat '''
C:\Windows\System32\OpenSSH\ssh.exe -vvv -F \users\jenkins\.ssh\config -I \Users\jenkins\.ssh\id_rsa -o StrictHostKeyChecking=no XXXXXXXXX@XXXXXXXXXXXXXXXXXX echo âConnection Successfulâ exit
'''
You specified the path to the config and key without a drive, now if the agent runs on drive D: then -F \users\jenkins\.ssh\config
is not found.
PS: It will really help if you format code and logout, you can use markdown here
Use Case:
We are currently working on an EC2-Fleet Windows node that requires SSH access for two purposes:
Below script is working fine to connect to another remote server via ssh.
pipeline {
agent {
label âwindow-ssh-test-nodeâ
}
stages {
stage(âPrepare SSH Script and Connectâ) {
steps {
withCredentials([sshUserPrivateKey(
credentialsId: âec2_node_test_hostingâ,
usernameVariable: âSSH_USERâ,
keyFileVariable: âSSH_KEYFILEâ
)]) {
script {
writeFile file: âssh_connection.shâ, text: âââ#!/bin/bash
ssh -i â$1â -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null â$2@$3â âhostname && uptime && ls -lâ
âââ
}
bat âââ
set SSH_REMOTE_HOST=XXXXXXX.XXXXXXXXXXXXg.com
call âC:\Program Files\Git\bin\bash.exeâ -c âchmod +x ./ssh_connection.sh && ./ssh_connection.sh "%SSH_KEYFILE%" "%SSH_USER%" "%SSH_REMOTE_HOST%"â
âââ
}
}
}
}
}
We have issues to clone from bitbucket repository
pipeline {
agent {
label âwindow-ssh-test-nodeâ
}
environment {
GIT_SSH_COMMAND = 'ssh -i C:\\Users\\Administrator\\.ssh\\bitbucket_key -o StrictHostKeyChecking=no'
}
stages {
stage('Checkout Repo') {
steps {
// Copy SSH private key from Jenkins credentials
withCredentials([sshUserPrivateKey(credentialsId: XXXXXXXXXXXXXXXXXX', keyFileVariable: 'KEYFILE')]) {
bat """
mkdir %USERPROFILE%\\.ssh
copy %KEYFILE% %USERPROFILE%\\.ssh\\bitbucket_key
git config --global core.sshCommand "ssh -i %USERPROFILE%\\.ssh\\bitbucket_key -o StrictHostKeyChecking=no"
git clone ssh://git@XXXXXXXXXXXXXXXX.com:7999/pts/webhook.git
"""
}
}
}
}
}
Can you pls help us to clone from Bitbucket.
HI,
When trying to clone getting ââSSH-2.0-OpenSSH_9.1â is not recognized as an internal or external command, operable program or batch file.â
Despite this, Jenkins seems unable to recognize or execute the SSH command properly. Iâve verified environment variables, and OpenSSH is accessible from the command line. The agent setup is failing when trying to establish an SSH connection.
Any help or guidance on resolving this issue would be greatly appreciated.
Use the checkout
step for cloning from bitbucket instead of trying to do that in your own manually
We are planning to use Jenkins EC2-Fleet with Windows nodes and would like to perform Bitbucket clone operations via SSH within the pipeline. Please let us know if there are any specific configurations or prerequisites required for this setup.