我们正在使用 jenkins-job-builder 来生成 jenkins 作业,当我们尝试使用 ssh-credentials 插件时,我们遇到了一个持续的问题。当我们创建一个尝试使用 ssh 密钥的新作业时,该作业会失败,
java.io.IOException: [ssh-agent] Could not find specified credentials
但如果我们点击它Configure
并Save
开始工作。
在 credentials.xml 中,密钥定义如下所示:
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials@1.15">
<scope>GLOBAL</scope>
<id>jenkins-key</id>
<description>Jenkins user private key</description>
<username>root</username>
<privateKeySource class="com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource">
<privateKey>{A_WORKING_PRIVATE_KEY}</privateKey>
</privateKeySource>
</com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey>
关于文档(https://docs.openstack.org/infra/jenkins-job-builder/wrappers.html?highlight=credentials#wrappers.ssh-agent-credentials)使用已定义凭证的作业定义应如下所示:
- wrapper:
name: jenkins-key
wrappers:
- ssh-agent-credentials:
user: 'root'
[...]
- job:
name: jobxyz
disabled: false
project-type: freestyle
node: jenkins-slave
wrappers:
- jenkins-key
builders:
- shell: |
[...]
生成的作业 xml 中的相应部分如下所示:
<buildWrappers>
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
<user>root</user>
<ignoreMissing>false</ignoreMissing>
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
</buildWrappers>
但是当我们尝试运行作业时,我们会收到上述错误:
FATAL:
java.io.IOException: [ssh-agent] Could not find specified credentials
at com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper.preCheckout(SSHAgentBuildWrapper.java:209)
at jenkins.scm.SCMCheckoutStrategy.preCheckout(SCMCheckoutStrategy.java:76)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:498)
at hudson.model.Run.execute(Run.java:1818)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
FATAL: [ssh-agent] Could not find specified credentials
java.io.IOException: [ssh-agent] Could not find specified credentials
at com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper.preCheckout(SSHAgentBuildWrapper.java:209)
at jenkins.scm.SCMCheckoutStrategy.preCheckout(SCMCheckoutStrategy.java:76)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:498)
at hudson.model.Run.execute(Run.java:1818)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
如果我们访问 jenkins 网页,并且在configure & save
不更改任何配置的情况下点击,则作业的新 xml 将更改为:
<buildWrappers>
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper plugin="ssh-agent@1.17">
<credentialIds>
<string>jenkins-key</string>
</credentialIds>
<ignoreMissing>false</ignoreMissing>
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
</buildWrappers>
我很确定这不应该像这样工作,但我有点不确定下一步该做什么。以下是一些版本:
Jenkins Job Builder 版本:2.10.1
詹金斯版 2.172
SSH 凭证版本:1.15