Skip to content

Support https://docs.gitlab.com/api/jobs/#get-job-tokens-job in JobApi #1231

Closed
@tkruse

Description

@tkruse

The actual gitlab v4 API allows to fetch jobs by token https://docs.gitlab.com/api/jobs/#get-job-tokens-job

curl --header "Authorization: Bearer $CI_JOB_TOKEN" "${CI_API_V4_URL}/job"
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" "${CI_API_V4_URL}/job"
curl "${CI_API_V4_URL}/job?job_token=$CI_JOB_TOKEN"

But the Java API does not have any way to access that endpoint.

Implementation would be roughly:

    /**
     * GET /job
     * curl "${CI_API_V4_URL}/job?job_token=$CI_JOB_TOKEN" or 
     * curl --header "JOB-TOKEN: $CI_JOB_TOKEN" "${CI_API_V4_URL}/job"
     */
    public Job getJob(final String ciJobToken) throws GitLabApiException {
        // this method is currently not exposed in JobApi
        final Response response = get(
                Response.Status.OK, 
                // this approach collides with other authorization tokens in gitlabApi
                // new GitLabApiForm().withParam("job_token", ciJobToken).asMap(), 
               null
                "job");
        return (response.readEntity(new GenericType<Job>() {}));
    }

However, we had trouble implementing it like this, because the authorization via the job_token and the authorization via the personal access token seemed to conflict with each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions