将jenkins config.xml转换为yaml以在jenkins_job_builder中使用

时间:2018-02-08 17:34:03

标签: python jenkins ansible yaml jenkins-job-builder

我正在使用jenkins-job-builder来生成jenkins职位。

我向我的jenkins添加了ansible插件,我希望将其用作我的部署工具。

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

没有extraVarslimit,我的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>

我知道,我遗漏了limitextraVars没有将yaml转换为正确xml的内容。

我可以更改哪个jenkins-job-builder生成适当的xml?

0 个答案:

没有答案