impossible to download artifacts that are not json-formated

Bug #1973243 reported by gdemengin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Jenkins
Fix Released
Undecided
Unassigned

Bug Description

get_build_artifact allows to get artifacts if they are JSON files
but if they are non-json ascii files or binary files it fails

for example run this pipeline:

```
node {
    sh '''
        echo text > ascii.txt
        dd if=/dev/zero of=binary.dat bs=1c count=10
        ls -l
        cat ascii.txt
        cat binary.dat | hexdump
    '''
    writeJSON file: 'data.json', json: [ 'key': 'val']
    archiveArtifacts 'ascii.txt'
    archiveArtifacts 'binary.dat'
    archiveArtifacts 'data.json'

}
```

json artifact can be downloaded

```
>>> import jenkins
>>> j = jenkins.Jenkins('http://ci.jenkins.internal:8080/', 'jenkins', 'jenkins')
>>> data = j.get_build_artifact('testjob', '1', 'data.json')
>>> print(data)
{'key': 'val'}
```

but not the binary one

```
>>> binary = j.get_build_artifact('testjob', '1', 'binary.dat')
Traceback (most recent call last):
  File "/workspace/python-jenkins/jenkins/__init__.py", line 731, in get_build_artifact
    return json.loads(response)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspace/python-jenkins/jenkins/__init__.py", line 737, in get_build_artifact
    raise JenkinsException(
jenkins.JenkinsException: Could not parse JSON info for job[testjob] number[1]
```

nor the ascii (non-jenkins) one

```
>>> ascii = j.get_build_artifact('testjob', '1', 'ascii.txt')
Traceback (most recent call last):
  File "/workspace/python-jenkins/jenkins/__init__.py", line 731, in get_build_artifact
    return json.loads(response)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspace/python-jenkins/jenkins/__init__.py", line 737, in get_build_artifact
    raise JenkinsException(
jenkins.JenkinsException: Could not parse JSON info for job[testjob] number[1]
``

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-jenkins (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/jjb/python-jenkins/+/841640

Changed in python-jenkins:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-jenkins (master)

Reviewed: https://review.opendev.org/c/jjb/python-jenkins/+/841640
Committed: https://opendev.org/jjb/python-jenkins/commit/5c44d7c9ecc6d8e92a935ac7b3a0262016d6ebb0
Submitter: "Zuul (22348)"
Branch: master

commit 5c44d7c9ecc6d8e92a935ac7b3a0262016d6ebb0
Author: Guillaume DeMengin <email address hidden>
Date: Sat Nov 26 19:35:37 2022 +0100

    get_build_artifact_as_bytes to support non-json files

    new function get_build_artifact_as_bytes to replace get_build_artifact (incompatible with artifacts not json-formatted)
    + use a stream to download binary artifacts

    all artifacts are returned as bytes to avoid encoding issues
    and an exception NotFoundException is raised in case of missing artifact

    Closes-Bug: #1973243
    Change-Id: I24ce4ecd854f8a19ed4d760404adb7d1ac6b5509

Changed in python-jenkins:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.