Skip to content
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

Add JobApi#getJob() #1233

Merged
merged 2 commits into from
Mar 5, 2025
Merged
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
13 changes: 13 additions & 0 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId, Boolea
return (getJobsForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage(), includeRetried).stream());
}

/**
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable (Using a {@link org.gitlab4j.models.Constants.TokenType#JOB_TOKEN} authentication).
*
* <pre><code>GitLab Endpoint: GET /job</code></pre>
*
* @return a single job
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend adding more explanation that this will only work while the CI_JOB_TOKEN is valid (while the CI job is running) or similar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1236

* @throws GitLabApiException if any exception occurs during execution
*/
public Job getJob() throws GitLabApiException {
Response response = get(Response.Status.OK, null, "job");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend checking that a JOB_TOKEN was set in gitlabApi and throwing a meaningful exception if not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added with #1236

return (response.readEntity(Job.class));
}

/**
* Get single job in a project.
*
Expand Down