首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jenkins Pipeline - ssh-agent找不到凭据

Jenkins Pipeline - ssh-agent找不到凭据
EN

Stack Overflow用户
提问于 2019-10-21 21:35:20
回答 2查看 2K关注 0票数 0

我有一个任务,一直在通过GUI作为Freestyle项目工作。我试图按照我能找到的所有说明和文档将其转换为Pipeline作业,但我收到了错误。

以下是我为该操作创建的凭据。

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

代码语言:javascript
复制
#!/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"

                    """
                }
            }
        }

    }
}

最后,这里是输出日志。

代码语言:javascript
复制
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服务器上运行多个命令。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-10-21 23:40:46

这可能与JENKINS-32101有关。请尝试其他语法sshagent(['1c0972a6-2bbf-4144-XXXX-XXXXXXXXXXXX']) {...}

票数 0
EN

Stack Overflow用户

发布于 2020-11-17 17:53:50

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

要发现这些信息并不容易,但您可以发现plugin documentation显示“请注意,只能使用基于私钥的凭据”。

如果您指定的凭据id引用了"Username with password“类型的凭据,则始终会得到"FATAL: ssh-agent找不到指定的凭据”

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58487491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档