0

I have a task that's been working through the GUI as a Freestyle project. I'm trying to follow all of the instructions and documentation I can find to convert it to a Pipeline job, but I'm getting errors.

Here are the credentials I've created for the action. enter image description here

I'm trying a fairly simple test to run a command on a remote Windows server.

#!/usr/bin/env groovy

pipeline {
    agent any
    stages {
        stage("build") {
            steps {
                sshagent(credentials: ['1c0972a6-2bbf-4144-XXXX-XXXXXXXXXXXX']) {
                    sh """

                        ssh "dev user@XX.XX.XX.XX" su -c "powershell /project/getproj.bat | tee build.log"

                    """
                }
            }
        }

    }
}

Finally, heres the output log.

Started by user XXXX XXXX
Obtained Jenkinsfile from git https://xx.xx.com/xxxx.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/Testing/xxxx
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential 0d240009-1e30-4e3b-xxxx-xxxxxxxxxxxx
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://xx.xx.com/xxxx.git # timeout=10
Fetching upstream changes from https://xx.xx.com/xxxx.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress https://xx.xx.com/xxxx.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/convert_jenkinsfile^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/convert_jenkinsfile^{commit} # timeout=10
Checking out Revision 40a510567b52ce621cb6590ab233289cb1948ad4 (refs/remotes/origin/convert_jenkinsfile)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 40a510567b52ce621cb6590ab233289cb1948ad4
Commit message: "Update Jenkinsfile"
 > git rev-list --no-walk 6325e08c341a4e7e0cec8538640bd3d6cf6941fa # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] sshagent
FATAL: [ssh-agent] Could not find specified credentials
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-pRQqteq1L7US/agent.49961
SSH_AGENT_PID=49964
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ ssh dev user@xx.xx.xx.xx su -c powershell /project/getproj.bat | tee build.log
Host key verification failed.
[Pipeline] }
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 49964 killed;
[ssh-agent] Stopped.
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE

I can't tell if I'm doing something wrong with how I've identified the credentials, or there's something wrong in the Jenkinsfile. I'm intending to run multiple commands on the remote Windows server.

user1209675
  • 296
  • 7
  • 18

2 Answers2

1

The ssh-agent plugin does not support user/password credentials.

It is not so easy to spot this information, but you can find that the plugin documentation says 'Note that only Private Key based credentials can be used.'

If you specify a credentials id referring to credentials of kind "Username with password", you always get "FATAL: [ssh-agent] Could not find specified credentials"

fabiomina
  • 11
  • 1
0

This might be related to JENKINS-32101. Please try the alternative syntax sshagent(['1c0972a6-2bbf-4144-XXXX-XXXXXXXXXXXX']) {...}.

Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25
  • Changing the syntax does help the error I was getting. However, it's now getting an error on the ssh line when it authenticates there. ''' #!/usr/bin/env groovy pipeline { agent any stages { stage("build") { steps { sshagent(['1c0972a6-2bbf-4144-8f81-6840f10bce2e']) { sh "ssh -o StrictHostKeyChecking=no 'dev user@10.72.46.209' 'powershell /project/getproj.bat' " } } } } } ''' – user1209675 Oct 21 '19 at 16:43
  • Permission denied (publickey,password,keyboard-interactive). – user1209675 Oct 21 '19 at 17:14
  • Check this out https://stackoverflow.com/questions/1556056/permission-denied-publickey-keyboard-interactive – Dibakar Aditya Oct 21 '19 at 17:18
  • I logged into the Docker container running Jenkins and was able to ssh into the remote host using the username and password I'm using in Jenkins. That makes me think that the suggestions in the link aren't applicable. – user1209675 Oct 21 '19 at 18:16