1

我正在使用jenkins-job-builder来生成 jenkins 工作。

我在我的 jenkins 中添加了ansible插件,我想用它作为我的部署工具。

当我开始转换builder我的工作部分时,yaml它适用于大多数元素。但是,我无法将Extra Variablesor转换extraVars为yaml。limitconfig.xml

没有extraVarsand limit,我的 yaml 如下。

builders:
    - ansible-playbook:
        playbook: my_playbook.yaml
        inventory:
            path: '{host_file}'
        sudo: true

我的工作的config.xml构建器节点为

<builders>
    <org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder plugin="ansible@0.8">
      <playbook>my_playbook.yaml</playbook>
      <inventory class="org.jenkinsci.plugins.ansible.InventoryPath">
        <path>hosts</path>
      </inventory>
      <limit>myhost</limit>
      <tags></tags>
      <skippedTags></skippedTags>
      <startAtTask></startAtTask>
      <credentialsId></credentialsId>
      <vaultCredentialsId></vaultCredentialsId>
      <sudo>true</sudo>
      <sudoUser></sudoUser>
      <forks>5</forks>
      <unbufferedOutput>true</unbufferedOutput>
      <colorizedOutput>false</colorizedOutput>
      <hostKeyChecking>false</hostKeyChecking>
      <additionalParameters>-b --become-method su --become-user root -u rack --extra-vars &quot;ansible_ssh_pass=************&quot; --extra-vars &quot;ansible_become_pass=************&quot;</additionalParameters>
      <copyCredentialsInWorkspace>false</copyCredentialsInWorkspace>
      <extraVars>
        <org.jenkinsci.plugins.ansible.ExtraVar>
          <key>ldap_password</key>
          <value>*******</value>
          <hidden>false</hidden>
        </org.jenkinsci.plugins.ansible.ExtraVar>
      </extraVars>
    </org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder>
</builders>

我试图添加limitextraVars

builders:
    - ansible-playbook:
        playbook: my_playbook.yaml
        inventory:
            path: '{host_file}'
        sudo: true
        limit: myhost
        extra-vars:
            key: ldap_password
            value: ********

但这不起作用。

我尝试了How to convert jenkins job configuration config.xml to YAML format in python to be used jenkins-job-builder中给出的答案?

Answer1给出了错误logRotator

Answer2仅作为 xml 给出。

builders:
    - raw:
        xml: |
            <org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder plugin="ansible@0.8">
              <playbook>my_playbook.yaml</playbook>
              <inventory class="org.jenkinsci.plugins.ansible.InventoryPath">
                <path>hosts</path>
              </inventory>
              <limit>myhost</limit>
              <tags></tags>
              <skippedTags></skippedTags>
              <startAtTask></startAtTask>
              <credentialsId></credentialsId>
              <vaultCredentialsId></vaultCredentialsId>
              <sudo>true</sudo>
              <sudoUser></sudoUser>
              <forks>5</forks>
              <unbufferedOutput>true</unbufferedOutput>
              <colorizedOutput>false</colorizedOutput>
              <hostKeyChecking>false</hostKeyChecking>
              <additionalParameters>-b --become-method su --become-user root -u rack --extra-vars &quot;ansible_ssh_pass=************&quot; --extra-vars &quot;ansible_become_pass=************&quot;</additionalParameters>
              <copyCredentialsInWorkspace>false</copyCredentialsInWorkspace>
              <extraVars>
                <org.jenkinsci.plugins.ansible.ExtraVar>
                  <key>ldap_password</key>
                  <value>*******</value>
                  <hidden>false</hidden>
                </org.jenkinsci.plugins.ansible.ExtraVar>
              </extraVars>
    </org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder>

我知道,我错过了一些东西,limit并且extraVars没有转换yaml为正确的xml.

我可以改变什么,通过它jenkins-job-builder生成正确的xml?

4

0 回答 0