1

I am using jenkins-job-builder to generate jenkins jobs.

I added ansible plugin to my jenkins, and I want to use that as my deployment tool.

When I start converting builder section of my job in yaml it works fine for most of the element. But, I am not able to convert Extra Variables or extraVars and limit in config.xml to yaml.

Without extraVars and limit, my yaml as below.

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

My job's config.xml has builder node as

<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>

I tried to add limit and extraVars.

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

But that not works.

I tried answers given in How to convert jenkins job configuration config.xml to YAML format in python to be used jenkins-job-builder?

Answer1 gives error for logRotator

Answer2 gives as xml only.

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>

I know, I am missing something for limit and extraVars which is not converting yaml to proper xml.

What I can change, by which jenkins-job-builder generate proper xml?

Nilesh
  • 20,521
  • 16
  • 92
  • 148

0 Answers0