Unable to create jenkins job using anisble

121 views
Skip to first unread message

Narmada Karthika

unread,
Jun 12, 2023, 9:02:29 PM6/12/23
to Ansible Project
I am trying to create a jenkins job using ansible "community.general.jenkins_job", but I am getting below error. Also I used existing job config.xml

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_community.general.jenkins_job_payload_jul5utxw/ansible_community.general.jenkins_job_payload.zip/ansible_collections/community/general/plugins/modules/jenkins_job.py", line 313, in create_job
  File "/tmp/ansible_community.general.jenkins_job_payload_jul5utxw/ansible_community.general.jenkins_job_payload.zip/ansible_collections/community/general/plugins/modules/jenkins_job.py", line 245, in get_config
  File "/tmp/ansible_community.general.jenkins_job_payload_jul5utxw/ansible_community.general.jenkins_job_payload.zip/ansible_collections/community/general/plugins/modules/jenkins_job.py", line 350, in job_config_to_string
  File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1314, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "config": "/home/teamci-deploy-user/gitrepo/jenkins/build.com/config.xml",
            "enabled": null,
            "name": "axwarpsynctest",
            "password": null,
            "state": "present",
            "token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "url": "https://build.com",
            "user": "nchi...@domain.com",
            "validate_certs": true
        }
    },
    "msg": "Unable to create job, not well-formed (invalid token): line 1, column 0 for https://build.com"
}

Abhijeet Kasurde

unread,
Jun 12, 2023, 9:36:03 PM6/12/23
to ansible...@googlegroups.com
Seems like the config.xml is not well formatted.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2a8ac6a5-c01b-44ff-abff-fca38ad9cbc8n%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Jiale Lin

unread,
Jun 13, 2023, 12:20:24 AM6/13/23
to Ansible Project
#!/bin/bash

check_xml_syntax() {
file_path=$1
if xmllint --noout "$file_path" &>/dev/null; then
echo "XML syntax is valid."
return 0
else
echo "Invalid XML syntax: $(xmllint --errors "$file_path")"
return 1
fi
}

format_xml() {
file_path=$1
xmllint --format --output "$file_path" "$file_path" &>/dev/null
echo "XML file formatted successfully."
}

config_file_path="/home/teamci-deploy-user/gitrepo/jenkins/build.com/config.xml"

# Check XML syntax
if ! check_xml_syntax "$config_file_path"; then
exit 1
fi

format_xml "$config_file_path"


Narmada Karthika

unread,
Jun 13, 2023, 2:02:24 AM6/13/23
to ansible...@googlegroups.com
It says that, but I did not touch the configuration.xml, I just used the conf from the existing Jenkins job.

--
 Thanks,
Narmada Karthika Chitturi
 

Narmada Karthika

unread,
Jun 13, 2023, 2:03:17 AM6/13/23
to ansible...@googlegroups.com
Thankyou will try this 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Narmada Karthika

unread,
Jun 13, 2023, 12:53:31 PM6/13/23
to ansible...@googlegroups.com
I tried this but getting below error
Unknown option --errors
Invalid XML syntax: Usage : xmllint [options] XMLfiles ...

On Mon, Jun 12, 2023 at 9:20 PM Jiale Lin <jeremy...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e1f5beeb-6533-4271-9044-36f4b4ccb6f5n%40googlegroups.com.

Dick Visser

unread,
Jun 13, 2023, 1:10:11 PM6/13/23
to ansible...@googlegroups.com
Just try plain xmllint, you're now debugging someone else's script.

xmllint path/to/configuration.xml







Narmada Karthika

unread,
Jun 13, 2023, 3:06:17 PM6/13/23
to Ansible Project
thankyou, 
I tried xmllint >config.xml>
it did not  throw any warning or error, still I am getting same error, also I tried to get basic config.xml and tired.no use

Narmada Karthika

unread,
Jun 13, 2023, 3:26:07 PM6/13/23
to Ansible Project
it is showing error at the below  point , do I need to use any other version of python?

File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1314, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
fatal: [localhost]: FAILED! => {

Abhijeet Kasurde

unread,
Jun 13, 2023, 3:46:40 PM6/13/23
to ansible...@googlegroups.com
Please use the file lookup plugin to read config xml instead of just the filename like -

config: "{{ lookup('file', 'templates/test.xml') }}"



--
Thanks,
Abhijeet Kasurde

Narmada Karthika

unread,
Jun 13, 2023, 6:16:12 PM6/13/23
to Ansible Project
Thank you Abhijeet, I tried your option, it stopped complaining about config errors
second error what I fixed is the user which I am trying to use is not admin on jenkins, after granting access, I am able to configure the job

Thanks a lot every one.

Reply all
Reply to author
Forward
0 new messages