How to Create HP QC Defect from Jenkins Programmatically

Micro Focus Quality Center, formerly known as HP Quality Center is a quality management software. You can go through https://www.microfocus.com/en-us/products/alm-quality-center/overview to find out the benefits provided by ALM QC

I had a requirement to create a QC defect through Jenkins, It was on the old HP ALM environment when QC was not taken over by MicroFocus where I faced a few issues which I was able to resolve.

I created a Jenkins Job and configured it as shown in the below screenshots.

jenkins qc creation 1 - DevOpsBuzz
jenkins qc creation 2 - DevOpsBuzz
jenkins qc creation 3 - DevOpsBuzz
jenkins qc creation 4 - DevOpsBuzz
jenkins qc creation 5 - DevOpsBuzz

I provided the XML input to my curl command which will create QC defect based on provided Jenkins parameters.

jenkins qc creation 6 - DevOpsBuzz
jenkins qc creation 7 - DevOpsBuzz
jenkins qc creation 8 - DevOpsBuzz

After configuring the Job. Saved the Job and Triggered the job by the ‘Build with Parameters’ option.

jenkins qc creation 9 e1585694492983 - DevOpsBuzz

Provide all the parameters.

jenkins qc creation 10 - DevOpsBuzz
jenkins qc creation 11 - DevOpsBuzz

The build was completed and Verified the Console output.

jenkins qc creation 12 - DevOpsBuzz
jenkins qc creation 13 - DevOpsBuzz

Now, the above can be considered as the happy path which will help you to create the QC defect programmatically either by Jenkins or any other tools, but I found a few issues when I was writing the code for the same and would like to share as it was quite interesting 🙂

Initially, I followed the official guides and tried to authenticate:

curl -c qc_cookies -u admin:********  http://qcserver:8084/qcbin/authentication-point/authenticate

By which I was able to authenticate (tried in both browser and curl). To verify my authentication, I used:

curl --cookie cookies.txt --cookie-jar cookies.txt  http://localhost:8084/qcbin/rest/is-authenticated

It was showing the user name as part of authentication. So I was pretty sure my connection is established and I got the right cookies.

Then I tried to list out the defects – to do that I used:

curl --cookie cookies.txt --cookie-jar cookies.txt  http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects

But when you hit the API, the login was not remaining authenticated and it’s asking for a new login, which was not working and giving different errors, such as:

401 – with login not given

302 – since it was redirecting to the login page

Then I checked the 12.53 REST APIs documentation: I got to know about one more term – Instead of using rest in URL – I tried with API.

After reviewing it, I fired:

curl -c qc_cookies -u admin:******  http://qcserver:8084/qcbin/api/authentication-point/authenticate 

It prompted me to try with sign-in URL, then I changed my command to this:

curl -c qc_cookies -u admin:********  http://qcserver:8084/qcbin/api/authentication/sign-in -v

I had then verified with this:

curl -b qc_cookies http://localhost:8084/qcbin/rest/is-authenticated

I had then listed out the defects:

curl -b qc_cookies -c qc_cookies -H "Content-Type: application/json" -X GET http://qcserver:8084/qcbin/api/domains/DOM/projects/PROJ/defects

It has successfully shown the defects.

But when I fired this create defect command it was throwing an error:

HTTP/1.1 415 Unsupported Media Type: "Id":"qccore.general-error","Title":"Unsupported Media Type"
curl -b qc_cookies -c qc_cookies -X POST -d @post-defect.json http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects/ -v

I found a nice explanation which states:

It looks like the issue has to do with the difference between the Content-Type and Accept headers. In HTTP, Content-Type is used in request and response payloads to convey the media type of the current payload. Accept is used in request payloads to say what media types the server may use in the response payload.

So, having a Content-Type in a request without a body (like your GET request) has no meaning. When you do a POST request, you are sending a message body, so the Content-Type does matter.

If a server is not able to process the Content-Type of the request, it will return a 415 HTTP error. (If a server is not able to satisfy any of the media types in the request Accept header, it will return a 406 error.)

In OData v3, the media type “application/json” is interpreted to mean the new JSON format (“JSON light”).

If the server does not support reading JSON light, it will throw a 415 error when it sees that the incoming request is JSON light.

In your payload, your request body is verbose JSON, not JSON light, so the server should be able to process your request. It just doesn’t because it sees the JSON light content type.

I made a few changes and tried with JSON and XML but it was not helping and even got 500 Errors – then I made it in original form and changed the headers to show the odata verbose:

curl -b qc_cookies -c qc_cookies -H "Accept: application/xml;odata=verbose" -H "Content-Type: application/xml" -X POST -d @post-defect.xml http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects

It showed me what was wrong with my provided JSON or XML and once I fixed it – I was able to create the defect and used correct syntax in my Jenkins job.

Hope it helps you in creating HP QC defects from Jenkins…

Happy learning!

15 thoughts on “How to Create HP QC Defect from Jenkins Programmatically”

    1. Hi Ranadip,
      Sorry for the delay.
      The above mentioned powershell scripts are just to create a input file based on the QC defect parameters and to display the output.
      The main script is the windows batch one :- please find below

      curl -c qc_cookies -u admin:%password% http://qcserver:8084/qcbin/api/authentication/sign-in

      curl -b qc_cookies -c qc_cookies -H “Accept: application/xml;odata=verbose” -H “Content-Type: application/xml” -X POST -d @temp.xml http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects -o curl_output

      Hope this helps!!

  1. Hi Ravi,

    Thnx for your reply.
    I understand your point.
    I actually need XML payload to create defect. As this solution already tested and working I don’t want to search and try same over internet :).

    Regards,
    Ranadip

    1. Hi Ranadip,
      Thanks again but sorry, I don’t have that xml file with me. It was quite an old post and I had decommissioned that jenkins server long back.
      You may need to refer the screenshot and write it.

  2. Hi Ravi,

    Thnx. No issues.
    One more query – If I need to upload attachments also along with defects how can I do that via curl.

    Regards,
    Ranadip

  3. Hi Ravi,
    I am using below curl commands to create defect in ALM for a specific project and release. But I am getting below error –
    Can you please check if I did any mistake –
    “Id”: “qccore.general-error”,
    “Title”: “Unsupported Media Type”,

    Sign In – curl -c qc_cookies -u xxxx:xxx http://xxxx/qcbin/api/authentication/sign-in -v
    Autheticate – curl -b qc_cookies http://xxxx/qcbin/rest/is-authenticated

    Create Defect –
    curl -b qc_cookies -c qc_cookies -H “Accept: application/xml;odata=verbose” -H “Content-Type: application/xml” -X POST -d @createdefect.xml http://xxxx/qcbin/api/domains/DEFAULT/projects/CIA_UAT_2020/defects -v

    Same Error is also coming in POSTMAN when I am testing that

    1. Hi Ranadip,

      I had highlighted this error in this article (in last steps), please check and see if it works for you. Usually its relevant to your json or xml.

      Thanks

      1. Hi Ravi,

        Its working now. But now facing different issue. I am using below payload create defect. But in ALM apart from below fields they have another mandatory fields. I am unable to find out exact Field Name for all of them, so can use those in XML. Do you have any clue for that where can I find out those names.

        4-Low

        TestDefectDWTeam

        TestDefectDWTeam

        2020-09-14

        DummyProject

  4. Hi Ravi,

    I want to attach file with my defect. For that I got some clue in
    https://admhelp.microfocus.com/octane/en/15.0.40/Online/Content/API/Create_an_Attachment.htm#mt-item-0.

    Here is the curl command –
    curl -X POST \
    -H “ALM_OCTANE_TECH_PREVIEW: true” \
    -H “Content-Type: application/octet-stream” \
    -b cookies.txt \
    –data-binary @C:/my_files/my_uploaded_image.jpg \
    “http://:/api/shared_spaces//workspaces//attachments? \
    name=my_attached_image.jpg&owner_work_item=”
    But what is and ?
    I believe is defect id.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top