Unverified Commit 73f200a8 authored by Thomas's avatar Thomas Committed by GitHub
Browse files

Extend "playJob" to support "job_variables_attributes" (#836)

parent 358b8c9a
...@@ -9,15 +9,14 @@ import java.nio.file.StandardCopyOption; ...@@ -9,15 +9,14 @@ import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.gitlab4j.api.models.ArtifactsFile; import org.gitlab4j.api.models.ArtifactsFile;
import org.gitlab4j.api.models.Job; import org.gitlab4j.api.models.Job;
import org.gitlab4j.api.models.JobAttributes;
/** /**
* This class provides an entry point to all the GitLab API job calls. * This class provides an entry point to all the GitLab API job calls.
...@@ -532,9 +531,35 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -532,9 +531,35 @@ public class JobApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Job playJob(Object projectIdOrPath, Long jobId) throws GitLabApiException { public Job playJob(Object projectIdOrPath, Long jobId) throws GitLabApiException {
return playJob(projectIdOrPath, jobId, null);
}
/**
* Play specified job with parameters in a project.
*
* <pre>
* <code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/play</code>
* </pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID
* or path
* @param jobId the ID to play job
* @param jobAttributes attributes for the played job
* @return job instance which just played
* @throws GitLabApiException if any exception occurs during execution
*/
public Job playJob(Object projectIdOrPath, Long jobId, JobAttributes jobAttributes)
throws GitLabApiException {
Response response;
if (jobAttributes == null) {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play"); response = post(Status.CREATED, formData, "projects",
return (response.readEntity(Job.class)); getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
} else {
response = post(Status.CREATED, jobAttributes, "projects",
getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
}
return (response.readEntity(Job.class));
} }
/** /**
......
package org.gitlab4j.api.models;
import org.gitlab4j.api.utils.JacksonJson;
public class JobAttribute {
private String key;
private String value;
public JobAttribute(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
package org.gitlab4j.api.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import org.gitlab4j.api.utils.JacksonJson;
public class JobAttributes {
@JsonProperty("job_variables_attributes")
private List<JobAttribute> jobAttributes;
public JobAttributes(List<JobAttribute> jobAttributes) {
this.jobAttributes = jobAttributes;
}
public List<JobAttribute> getJobAttributes() {
return jobAttributes;
}
public void setJobAttributes(List<JobAttribute> jobAttributes) {
this.jobAttributes = jobAttributes;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment