Skip to content

Commit ec84b49

Browse files
committed
Added support for pipeline schedule variables (#326).
1 parent e82dfb0 commit ec84b49

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.gitlab4j.api.models.Pipeline;
1212
import org.gitlab4j.api.models.PipelineSchedule;
1313
import org.gitlab4j.api.models.PipelineStatus;
14+
import org.gitlab4j.api.models.Variable;
1415

1516
/**
1617
* This class provides an entry point to all the GitLab API pipeline calls.
@@ -456,4 +457,64 @@ public PipelineSchedule takeOwnershipPipelineSchedule(Object projectIdOrPath, In
456457
Response response = post(Response.Status.OK, "", "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId, "take_ownership");
457458
return (response.readEntity(PipelineSchedule.class));
458459
}
460+
461+
/**
462+
* Create a pipeline schedule variable.
463+
*
464+
* <pre><code>GitLab Endpoint: POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables</code></pre>
465+
*
466+
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
467+
* @param pipelineScheduleId the pipelineSchedule ID
468+
* @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed
469+
* @param value the value for the variable
470+
* @return a Pipeline instance with the newly created pipeline schedule variable
471+
* @throws GitLabApiException if any exception occurs during execution
472+
*/
473+
public Variable createPipelineScheduleVariable(Object projectIdOrPath, Integer pipelineScheduleId,
474+
String key, String value) throws GitLabApiException {
475+
476+
GitLabApiForm formData = new GitLabApiForm()
477+
.withParam("key", key, true)
478+
.withParam("value", value, true);
479+
Response response = post(Response.Status.CREATED, formData,
480+
"projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId, "variables");
481+
return (response.readEntity(Variable.class));
482+
}
483+
484+
/**
485+
* Update a pipeline schedule variable.
486+
*
487+
* <pre><code>GitLab Endpoint: PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key</code></pre>
488+
*
489+
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
490+
* @param pipelineScheduleId the pipelineSchedule ID
491+
* @param key the key of an existing pipeline schedule variable
492+
* @param value the new value for the variable
493+
* @return a Pipeline instance with the updated variable
494+
* @throws GitLabApiException if any exception occurs during execution
495+
*/
496+
public Variable updatePipelineScheduleVariable(Object projectIdOrPath, Integer pipelineScheduleId,
497+
String key, String value) throws GitLabApiException {
498+
499+
GitLabApiForm formData = new GitLabApiForm().withParam("value", value, true);
500+
Response response = this.putWithFormData(Response.Status.CREATED, formData,
501+
"projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId, "variables", key);
502+
return (response.readEntity(Variable.class));
503+
}
504+
505+
/**
506+
* Deletes a pipeline schedule variable.
507+
*
508+
* <pre><code>DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key</code></pre>
509+
*
510+
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
511+
* @param pipelineScheduleId the pipeline schedule ID
512+
* @param key the key of an existing pipeline schedule variable
513+
* @throws GitLabApiException if any exception occurs
514+
*/
515+
public void deletePipelineScheduleVariable(Object projectIdOrPath, Integer pipelineScheduleId, String key) throws GitLabApiException {
516+
Response.Status expectedStatus = (isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
517+
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath),
518+
"pipeline_schedules", pipelineScheduleId, "variables", key);
519+
}
459520
}

0 commit comments

Comments
 (0)