Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26f95f3

Browse files
authored
Merge pull request#1159 from python-gitlab/feat/project-artifacts
Feat: Project job artifacts for latest successful pipeline
2 parents0f42e32 +c2806d8 commit26f95f3

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

‎docs/gl_objects/pipelines_and_jobs.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ Get the artifacts of a job::
292292

293293
build_or_job.artifacts()
294294

295+
Get the artifacts of a job by its name from the latest successful pipeline of
296+
a branch or tag:
297+
298+
project.artifacts(ref_name='master', job='build')
299+
295300
..warning::
296301

297302
Artifacts are entirely stored in memory in this example.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/job_artifacts.html
3+
"""
4+
5+
importpytest
6+
importresponses
7+
8+
9+
ref_name="master"
10+
job="build"
11+
12+
13+
@pytest.fixture
14+
defresp_artifacts_by_ref_name(binary_content):
15+
url=f"http://localhost/api/v4/projects/1/jobs/artifacts/{ref_name}/download?job={job}"
16+
17+
withresponses.RequestsMock()asrsps:
18+
rsps.add(
19+
method=responses.GET,
20+
url=url,
21+
body=binary_content,
22+
content_type="application/octet-stream",
23+
status=200,
24+
)
25+
yieldrsps
26+
27+
28+
deftest_download_artifacts_by_ref_name(gl,binary_content,resp_artifacts_by_ref_name):
29+
project=gl.projects.get(1,lazy=True)
30+
artifacts=project.artifacts(ref_name=ref_name,job=job)
31+
assertartifacts==binary_content

‎gitlab/v4/objects.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5122,6 +5122,40 @@ def transfer_project(self, to_namespace, **kwargs):
51225122
path,post_data={"namespace":to_namespace},**kwargs
51235123
)
51245124

5125+
@cli.register_custom_action("Project", ("ref_name","job"), ("job_token",))
5126+
@exc.on_http_error(exc.GitlabGetError)
5127+
defartifacts(
5128+
self,ref_name,job,streamed=False,action=None,chunk_size=1024,**kwargs
5129+
):
5130+
"""Get the job artifacts archive from a specific tag or branch.
5131+
5132+
Args:
5133+
ref_name (str): Branch or tag name in repository. HEAD or SHA references
5134+
are not supported.
5135+
artifact_path (str): Path to a file inside the artifacts archive.
5136+
job (str): The name of the job.
5137+
job_token (str): Job token for multi-project pipeline triggers.
5138+
streamed (bool): If True the data will be processed by chunks of
5139+
`chunk_size` and each chunk is passed to `action` for
5140+
treatment
5141+
action (callable): Callable responsible of dealing with chunk of
5142+
data
5143+
chunk_size (int): Size of each chunk
5144+
**kwargs: Extra options to send to the server (e.g. sudo)
5145+
5146+
Raises:
5147+
GitlabAuthenticationError: If authentication is not correct
5148+
GitlabGetError: If the artifacts could not be retrieved
5149+
5150+
Returns:
5151+
str: The artifacts if `streamed` is False, None otherwise.
5152+
"""
5153+
path="/projects/%s/jobs/artifacts/%s/download"% (self.get_id(),ref_name)
5154+
result=self.manager.gitlab.http_get(
5155+
path,job=job,streamed=streamed,raw=True,**kwargs
5156+
)
5157+
returnutils.response_content(result,streamed,action,chunk_size)
5158+
51255159
@cli.register_custom_action("Project", ("ref_name","artifact_path","job"))
51265160
@exc.on_http_error(exc.GitlabGetError)
51275161
defartifact(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp