From b91e6dffd03e7ad21771a6a884e1687ee5cbb79d Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Wed, 5 Mar 2025 09:16:02 +0100 Subject: [PATCH 1/2] Add getJob() Fixes #1231 --- .../src/main/java/org/gitlab4j/api/JobApi.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java index 4271e2ddf..afb0e5489 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java @@ -291,6 +291,20 @@ public Stream getJobsStream(Object projectIdOrPath, long pipelineId, Boolea return (getJobsForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage(), includeRetried).stream()); } + /** + * Retrieve the job corresponding to the $CI_JOB_TOKEN environment variable (Using a {@link org.gitlab4j.models.Constants.TokenType#JOB_TOKEN} authentication). + * + *
GitLab Endpoint: GET /job
+ * + * @return a single job + * @throws GitLabApiException if any exception occurs during execution + */ + public Job getJob() throws GitLabApiException { + Response response = + get(Response.Status.OK, null, "job"); + return (response.readEntity(Job.class)); + } + /** * Get single job in a project. * From 1bddeca82eaad5e90d22151b3dfa138ead234fc2 Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Wed, 5 Mar 2025 09:24:59 +0100 Subject: [PATCH 2/2] Format code --- gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java index afb0e5489..5b4e30baf 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java @@ -300,11 +300,10 @@ public Stream getJobsStream(Object projectIdOrPath, long pipelineId, Boolea * @throws GitLabApiException if any exception occurs during execution */ public Job getJob() throws GitLabApiException { - Response response = - get(Response.Status.OK, null, "job"); + Response response = get(Response.Status.OK, null, "job"); return (response.readEntity(Job.class)); } - + /** * Get single job in a project. *