Skip to content

Commit 73f200a

Browse files
authored
Extend "playJob" to support "job_variables_attributes" (gitlab4j#836)
1 parent 358b8c9 commit 73f200a

File tree

3 files changed

+92
-4
lines changed

3 files changed

+92
-4
lines changed

src/main/java/org/gitlab4j/api/JobApi.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
import java.util.List;
1010
import java.util.Optional;
1111
import java.util.stream.Stream;
12-
1312
import javax.ws.rs.core.Form;
1413
import javax.ws.rs.core.GenericType;
1514
import javax.ws.rs.core.MediaType;
1615
import javax.ws.rs.core.Response;
1716
import javax.ws.rs.core.Response.Status;
18-
1917
import org.gitlab4j.api.models.ArtifactsFile;
2018
import org.gitlab4j.api.models.Job;
19+
import org.gitlab4j.api.models.JobAttributes;
2120

2221
/**
2322
* This class provides an entry point to all the GitLab API job calls.
@@ -532,9 +531,35 @@ public Job eraseJob(Object projectIdOrPath, Long jobId) throws GitLabApiExceptio
532531
* @throws GitLabApiException if any exception occurs during execution
533532
*/
534533
public Job playJob(Object projectIdOrPath, Long jobId) throws GitLabApiException {
534+
return playJob(projectIdOrPath, jobId, null);
535+
}
536+
537+
/**
538+
* Play specified job with parameters in a project.
539+
*
540+
* <pre>
541+
* <code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/play</code>
542+
* </pre>
543+
*
544+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID
545+
* or path
546+
* @param jobId the ID to play job
547+
* @param jobAttributes attributes for the played job
548+
* @return job instance which just played
549+
* @throws GitLabApiException if any exception occurs during execution
550+
*/
551+
public Job playJob(Object projectIdOrPath, Long jobId, JobAttributes jobAttributes)
552+
throws GitLabApiException {
553+
Response response;
554+
if (jobAttributes == null) {
535555
GitLabApiForm formData = null;
536-
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
537-
return (response.readEntity(Job.class));
556+
response = post(Status.CREATED, formData, "projects",
557+
getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
558+
} else {
559+
response = post(Status.CREATED, jobAttributes, "projects",
560+
getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
561+
}
562+
return (response.readEntity(Job.class));
538563
}
539564

540565
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.utils.JacksonJson;
4+
5+
public class JobAttribute {
6+
7+
private String key;
8+
private String value;
9+
10+
public JobAttribute(String key, String value) {
11+
this.key = key;
12+
this.value = value;
13+
}
14+
15+
public String getKey() {
16+
return key;
17+
}
18+
19+
public void setKey(String key) {
20+
this.key = key;
21+
}
22+
23+
public String getValue() {
24+
return value;
25+
}
26+
27+
public void setValue(String value) {
28+
this.value = value;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return (JacksonJson.toJsonString(this));
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.gitlab4j.api.models;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.util.List;
5+
import org.gitlab4j.api.utils.JacksonJson;
6+
7+
public class JobAttributes {
8+
9+
@JsonProperty("job_variables_attributes")
10+
private List<JobAttribute> jobAttributes;
11+
12+
public JobAttributes(List<JobAttribute> jobAttributes) {
13+
this.jobAttributes = jobAttributes;
14+
}
15+
16+
public List<JobAttribute> getJobAttributes() {
17+
return jobAttributes;
18+
}
19+
20+
public void setJobAttributes(List<JobAttribute> jobAttributes) {
21+
this.jobAttributes = jobAttributes;
22+
}
23+
24+
@Override
25+
public String toString() {
26+
return (JacksonJson.toJsonString(this));
27+
}
28+
}

0 commit comments

Comments
 (0)