gpt4 book ai didi

java - jenkins-job-builder 使用凭据插件时生成错误的 xml

转载 作者:行者123 更新时间:2023-12-02 02:36:47 24 4
gpt4 key购买 nike

我们正在使用 jenkins-job-builder 来生成 jenkins 作业,当我们尝试使用 ssh-credentials 插件时,我们遇到了一个持续的问题。当我们创建一个尝试使用 ssh key 的新作业时,该作业失败并显示java.io.IOException: [ssh-agent] 找不到指定的凭据,但如果我们点击配置保存,它就会开始工作。

在credentials.xml中, key 定义如下所示:


<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 网页,然后点击配置并保存而不更改配置中的任何内容,则作业的新 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 作业生成器版本:2.10.1

Jenkins 版本。 2.172

SSH 凭据版本:1.15

最佳答案

看来最终的解决方案是忘记使用凭证包装器,而是插入原始 xml:

wrappers:
- raw:
xml: |
<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>

这会生成正确的 xml。

关于java - jenkins-job-builder 使用凭据插件时生成错误的 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57199446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com