← Back to team overview

python-jenkins-developers team mailing list archive

[Bug 1973243] Re: impossible to download artifacts that are not json-formated

 

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 <gdemengin@xxxxxxxxx>
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

-- 
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1973243

Title:
  impossible to download artifacts that are not json-formated

Status in Python Jenkins:
  Fix Released

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1973243/+subscriptions



References