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