Skip to content

Add JobApi#getJob(String) #1236

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

Merged
merged 2 commits into from
Apr 22, 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
24 changes: 22 additions & 2 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,38 @@ public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId, Boolea
}

/**
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable (Using a {@link org.gitlab4j.models.Constants.TokenType#JOB_TOKEN} authentication).
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable (Using a {@link TokenType#JOB_TOKEN} authentication).
*
* <pre><code>GitLab Endpoint: GET /job</code></pre>
*
* @return a single job
* @return a single job corresponding to the token used for the authentication
* @throws GitLabApiException if any exception occurs during execution
*/
public Job getJob() throws GitLabApiException {
TokenType tokenType = getApiClient().getTokenType();
if (tokenType != TokenType.JOB_TOKEN) {
throw new IllegalStateException(
"This method can only be called with a " + TokenType.JOB_TOKEN + " authentication");
}
Response response = get(Response.Status.OK, null, "job");
return (response.readEntity(Job.class));
}

/**
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable. This works only when used without any authentication.
*
* <pre><code>GitLab Endpoint: GET /job?job_token=${ciJobToken}"</code></pre>
*
* @return a single job corresponding to the token passed as query parameter
* @throws GitLabApiException if any exception occurs during execution
*/
public Job getJob(final String ciJobToken) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("job_token", ciJobToken, true);

Response response = get(Response.Status.OK, formData.asMap(), "job");
return (response.readEntity(Job.class));
}

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