When trying to download an artifact file using the download_job_artifact_file, the response is incorrectly attempted to be JSON-parsed, and hence will fail for any non-JSON non-binary files.
[1] pry(main)> valid_json_file = client.download_job_artifact_file(27906257, 1399004917, 'output/artifact.json')
=> #<Gitlab::FileResponse:46760 {filename: "artifact.json"}>
[2] pry(main)> jpg_file = client.download_job_artifact_file(27906257, 1399004917, 'output/artifact.jpg')
=> #<Gitlab::FileResponse:46780 {filename: "artifact.jpg"}>
[3] pry(main)> number_only_text_file = client.download_job_artifact_file(27906257, 1399004917, 'output/artifact.numbers.txt')
=> true
[4] pry(main)> string_text_file = client.download_job_artifact_file(27906257, 1399004917, 'output/artifact.txt')
Gitlab::Error::Parsing: The response is not a valid JSON
from /home/balasankarc/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/gitlab-4.17.0/lib/gitlab/request.rb:37:in `rescue in decode'
Caused by JSON::ParserError: 809: unexpected token at 'HelloWorld'
from /home/balasankarc/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/common.rb:216:in `parse'
[5] pry(main)> invalid_json_file = client.download_job_artifact_file(27906257, 1399004917, 'output/artifact.invalid.json')
Gitlab::Error::Parsing: The response is not a valid JSON
from /home/balasankarc/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/gitlab-4.17.0/lib/gitlab/request.rb:37:in `rescue in decode'
Caused by JSON::ParserError: 809: unexpected token at 'Random String which is not valid JSOn
'
from /home/balasankarc/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/common.rb:216:in `parse'
When trying to download an artifact file using the
download_job_artifact_file
, the response is incorrectly attempted to be JSON-parsed, and hence will fail for any non-JSON non-binary files.Example: Try downloading artifacts from https://gitlab.com/balasankarc/test-gitlab-gem-artifact-download/-/jobs/1399004917. See example below
true
because JSON load failed and the|| {}
gets applied.