Skip to content

Commit 5a20858

Browse files
rubenvittjmini
andauthored
feat: add method for "run a scheduled pipeline immediately" (#914)
* feat(scheduled-pipeline): makes scheduled pipelines runnable * Update src/main/java/org/gitlab4j/api/PipelineApi.java Co-authored-by: Jérémie Bresson <[email protected]> * fix(scheduled-pipeline): change post()-call * Update src/main/java/org/gitlab4j/api/PipelineApi.java Co-authored-by: Jérémie Bresson <[email protected]> * Add missing import --------- Co-authored-by: Jérémie Bresson <[email protected]> Co-authored-by: Jeremie Bresson <[email protected]> Co-authored-by: Ruben Vitt <[email protected]>
1 parent 49e2f3f commit 5a20858

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Optional;
66
import java.util.stream.Stream;
77

8+
import javax.ws.rs.core.Form;
89
import javax.ws.rs.core.GenericType;
910
import javax.ws.rs.core.Response;
1011

@@ -546,6 +547,19 @@ public PipelineSchedule takeOwnershipPipelineSchedule(Object projectIdOrPath, Lo
546547
return (response.readEntity(PipelineSchedule.class));
547548
}
548549

550+
/**
551+
* Trigger a new scheduled pipeline, which runs immediately.
552+
*
553+
* <pre><code>POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play</code></pre>
554+
*
555+
* @param projectIdOrPath projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
556+
* @param pipelineScheduleId the pipelineSchedule instance id which should run immediately
557+
* @throws GitLabApiException if any exception occurs during execution
558+
*/
559+
public void playPipelineSchedule(Object projectIdOrPath, Long pipelineScheduleId) throws GitLabApiException {
560+
post(Response.Status.CREATED, (Form)null, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId, "play");
561+
}
562+
549563
/**
550564
* Create a pipeline schedule variable.
551565
*

src/test/java/org/gitlab4j/api/TestPipelineApi.java

+20
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ public void testCreateAndUpdateProjectPipeLineSchedule() throws GitLabApiExcepti
146146
assertTrue(scheduleDecriptions.contains(newScheduleDescription));
147147
}
148148

149+
@Test
150+
void testPlayScheduledPipeline() throws GitLabApiException {
151+
assertNotNull(testProject);
152+
153+
String scheduleDescription = SCHEDULE_DESCRIPTION + " - test playScheduledPipeline()";
154+
PipelineSchedule newPipelineSchedule = new PipelineSchedule();
155+
newPipelineSchedule.setDescription(scheduleDescription);
156+
newPipelineSchedule.setCron("3 4 * * *");
157+
newPipelineSchedule.setRef("master");
158+
PipelineSchedule createdPipelineSchedule = gitLabApi.getPipelineApi().createPipelineSchedule(testProject, newPipelineSchedule);
159+
assertNotNull(createdPipelineSchedule);
160+
161+
// Make sure the created schedule is present before playing
162+
List<PipelineSchedule> pipelineSchedules = gitLabApi.getPipelineApi().getPipelineSchedules(testProject);
163+
assertNotNull(pipelineSchedules);
164+
assertTrue(pipelineSchedules.stream().map(PipelineSchedule::getDescription).collect(toList()).contains(scheduleDescription));
165+
166+
gitLabApi.getPipelineApi().playPipelineSchedule(testProject, createdPipelineSchedule.getId());
167+
}
168+
149169
@Test
150170
public void testDeleteProjectPipeLineSchedule() throws GitLabApiException {
151171

0 commit comments

Comments
 (0)