Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NGitLab.Mock/Clients/JobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public byte[] GetJobArtifacts(int jobId)
throw new NotImplementedException();
}

public byte[] GetJobArtifact(int jobId, string path)
{
throw new NotImplementedException();
}

public IEnumerable<Models.Job> GetJobs(JobScopeMask scope)
{
return GetJobs(new JobQuery { Scope = scope });
Expand Down
23 changes: 23 additions & 0 deletions NGitLab.Tests/JobTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NGitLab.Models;
using NGitLab.Tests.Docker;
Expand Down Expand Up @@ -203,5 +204,27 @@ public async Task Test_get_job_artifacts()
Assert.IsNotEmpty(artifacts);
}
}

[Test]
[NGitLabRetry]
public async Task Test_get_job_artifact()
{
using var context = await GitLabTestContext.CreateAsync();
var project = context.CreateProject();
var jobsClient = context.Client.GetJobs(project.Id);
using (await context.StartRunnerForOneJobAsync(project.Id))
{
AddGitLabCiFile(context.Client, project);
var jobs = await GitLabTestContext.RetryUntilAsync(() => jobsClient.GetJobs(JobScopeMask.Success), jobs => jobs.Any(), TimeSpan.FromMinutes(2));
var job = jobs.Single();
Assert.AreEqual(JobStatus.Success, job.Status);

var artifact = jobsClient.GetJobArtifact(job.Id, "file0.txt");
Assert.IsNotEmpty(artifact);

var content = Encoding.ASCII.GetString(artifact).Trim();
Assert.AreEqual("test", content);
}
}
}
}
2 changes: 2 additions & 0 deletions NGitLab/IJobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface IJobClient

byte[] GetJobArtifacts(int jobId);

byte[] GetJobArtifact(int jobId, string path);

string GetTrace(int jobId);

Task<string> GetTraceAsync(int jobId, CancellationToken cancellationToken = default);
Expand Down
12 changes: 12 additions & 0 deletions NGitLab/Impl/JobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public byte[] GetJobArtifacts(int jobId)
return result;
}

public byte[] GetJobArtifact(int jobId, string path)
{
byte[] result = null;
_api.Get().Stream($"{_jobsPath}/{jobId.ToStringInvariant()}/artifacts/{path}", s =>
{
using var ms = new MemoryStream();
s.CopyTo(ms);
result = ms.ToArray();
});
return result;
}

public string GetTrace(int jobId)
{
var result = string.Empty;
Expand Down
2 changes: 2 additions & 0 deletions NGitLab/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ NGitLab.IIssueClient.TimeStatsAsync(int projectId, int issueIid, System.Threadin
NGitLab.IJobClient
NGitLab.IJobClient.Get(int jobId) -> NGitLab.Models.Job
NGitLab.IJobClient.GetAsync(int jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.Job>
NGitLab.IJobClient.GetJobArtifact(int jobId, string path) -> byte[]
NGitLab.IJobClient.GetJobArtifacts(int jobId) -> byte[]
NGitLab.IJobClient.GetJobs(NGitLab.Models.JobQuery query) -> System.Collections.Generic.IEnumerable<NGitLab.Models.Job>
NGitLab.IJobClient.GetJobs(NGitLab.Models.JobScopeMask scope) -> System.Collections.Generic.IEnumerable<NGitLab.Models.Job>
Expand Down Expand Up @@ -537,6 +538,7 @@ NGitLab.Impl.IssueClient.TimeStatsAsync(int projectId, int issueIid, System.Thre
NGitLab.Impl.JobClient
NGitLab.Impl.JobClient.Get(int jobId) -> NGitLab.Models.Job
NGitLab.Impl.JobClient.GetAsync(int jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.Job>
NGitLab.Impl.JobClient.GetJobArtifact(int jobId, string path) -> byte[]
NGitLab.Impl.JobClient.GetJobArtifacts(int jobId) -> byte[]
NGitLab.Impl.JobClient.GetJobs(NGitLab.Models.JobQuery query) -> System.Collections.Generic.IEnumerable<NGitLab.Models.Job>
NGitLab.Impl.JobClient.GetJobs(NGitLab.Models.JobScopeMask scope) -> System.Collections.Generic.IEnumerable<NGitLab.Models.Job>
Expand Down