Jenkins管道-ssh代理找不到凭据

时间:2019-10-21 13:35:19

标签: jenkins jenkins-pipeline

我有一个正在作为Freestyle项目通过GUI进行的任务。我正在尝试遵循所有找到的说明和文档,将其转换为管道作业,但出现错误。

这是我为该操作创建的凭据。 enter image description here

我正在尝试一个相当简单的测试,以便在远程Windows服务器上运行命令。

#!/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"

                    """
                }
            }
        }

    }
}

最后,这是输出日志。

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

我无法确定我在识别凭据方面是否做错了什么,或者Jenkinsfile中有什么问题。我打算在远程Windows服务器上运行多个命令。

2 个答案:

答案 0 :(得分:1)

ssh-agent插件不支持用户/密码凭据。

发现此信息并非易事,但是您会发现plugin documentation说“请注意,只能使用基于私钥的凭据。”

如果您指定的凭据ID引用的凭据类型为“带有密码的用户名”,则始终会显示“ FATAL:[ssh-agent]找不到指定的凭据”

答案 1 :(得分:0)

这可能与JENKINS-32101有关。请尝试使用其他语法$result = . { while ($true) { <# Generating long list of psobject #> } } | Tee-Object -FilePath 'fname.csv' | ...

相关问题