Skip to content

Job Artifact Retrieval Does Not Work #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
loganknecht opened this issue Jan 15, 2019 · 1 comment
Closed

Job Artifact Retrieval Does Not Work #683

loganknecht opened this issue Jan 15, 2019 · 1 comment
Milestone

Comments

@loganknecht
Copy link

loganknecht commented Jan 15, 2019

Hello, I'm not quite sure why this is failing. My understanding is I should be able to use the path correctly to retrieve the artifact, but it completely fails for me.

This may have something to do with the fact that my artifact has spaces in its path?

Description of the problem, including code/CLI snippet

I'm trying to download a single artifact from a pipeline job.

Expected Behavior

  • Get Pipeline
  • Get Pipeline Job
  • Convert Pipeline Job to a Job
  • Get the artifact by path from the job

Actual Behavior

  • Get Pipeline
  • Get Pipeline Job
  • Convert Pipeline Job to a Job
  • Get the artifact by path from the job, except it returns an error saying the attribute does not exist
(venv) ╭─user ~/Repositories/ExampleRepo  ‹feature/ci-ci-testing*› 
╰─$ python gitlab_artifact.py                                      1 ↵
Traceback (most recent call last):
  File "gitlab_artifact.py", line 60, in <module>
    main()
  File "gitlab_artifact.py", line 52, in main
    a = most_recent_job.artifact("ExampleRepo/cached_service_specs.json")
  File "/Users/lknecht/Repositories/ExampleRepo/venv/lib/python3.7/site-packages/gitlab/cli.py", line 43, in wrapped_f
    return f(*args, **kwargs)
  File "/Users/lknecht/Repositories/ExampleRepo/venv/lib/python3.7/site-packages/gitlab/exceptions.py", line 251, in wrapped_f
    return f(*args, **kwargs)
  File "/Users/lknecht/Repositories/ExampleRepo/venv/lib/python3.7/site-packages/gitlab/v4/objects.py", line 1397, in artifact
    return utils.response_content(result, streamed, action, chunk_size)
  File "/Users/lknecht/Repositories/ExampleRepo/venv/lib/python3.7/site-packages/gitlab/utils.py", line 28, in response_content
    return response.content
AttributeError: 'list' object has no attribute 'content'

Specifications

  • python-gitlab version: 1.7.0
  • API version you are using (v3/v4): Unknown
  • Gitlab server version (or gitlab.com): GitLab Enterprise Edition 11.6.3-ee

Here is the script I've written that is failing

# Python Standard Libraries
# N/A
# Third-Party Libraries
import gitlab
# Custom Libraries
# N/A

SERVER_URL = "<REDACTED>"
TOKEN = "<REDACTED>"

PROJECT_ID = <REDACTED>
ARTIFACT_JOB_NAME = "<REDACTED>"
ARTIFACT_NAME = "ExampleRepo/cached_service_specs.json"

def main():
    gitlab_client = gitlab.Gitlab(SERVER_URL, private_token=TOKEN)
    monitor_project = gitlab_client.projects.get(PROJECT_ID)

    pipelines = [pipeline
                 for pipeline in monitor_project.pipelines.list()
                 if len(pipeline.jobs.list()) > 0
                 for job in pipeline.jobs.list()
                 if job.attributes["name"] == ARTIFACT_JOB_NAME]

    if(not (len(pipelines) > 0)):
        raise Exception("No pipelines are available to retrieve artifacts from.")

    most_recent_pipeline = pipelines[0]
    most_recent_pipeline_job = most_recent_pipeline.jobs.list()[0]

    most_recent_job = monitor_project.jobs.get(most_recent_pipeline_job.id, lazy=True)


    artifact = most_recent_job.artifact(ARTIFACT_NAME)


main()
@loganknecht loganknecht changed the title Job Artifact Does Not Work Job Artifact Retrieval Does Not Work Jan 15, 2019
@gpocentek
Copy link
Contributor

Hi @loganknecht

The artifact you retrieve contains json data so python-gitlab interprets it instead of just returning the content as string. This shouldn't happen obviously.

I'll push a patch ASAP.

gpocentek pushed a commit that referenced this issue Jan 19, 2019
http_get always tries to interpret the retrieved data if the
content-type is json. In some cases (artifact download for instance)
this is not the expected behavior.

This patch changes http_get and download methods to always get the raw
data without parsing.

Closes #683
@gpocentek gpocentek added this to the v1.8.0 milestone Jan 19, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants