Commit 22cf6801 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'rs-scheduled-pipeline-play-api' into 'master'

Add API to "Play" a scheduled pipeline immediately

Closes #201786

See merge request gitlab-org/gitlab!23718
parents 213d5094 3f4bda45
---
title: Add API to "Play" a scheduled pipeline immediately
merge_request: 23718
author:
type: added
...@@ -279,6 +279,36 @@ curl --request DELETE --header "PRIVATE-TOKEN: k5ESFgWY2Qf5xEvDcFxZ" "https://gi ...@@ -279,6 +279,36 @@ curl --request DELETE --header "PRIVATE-TOKEN: k5ESFgWY2Qf5xEvDcFxZ" "https://gi
} }
``` ```
## Run a scheduled pipeline immediately
> [Introduced](https://gitlab.com/gitlab-org/gitlab/issues/201786) in GitLab 12.8.
Trigger a new scheduled pipeline, which runs immediately. The next scheduled run
of this pipeline is not affected.
```text
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play
```
| Attribute | Type | required | Description |
| ---------------- | --------- | ---------- | -------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `pipeline_schedule_id` | integer | yes | The pipeline schedule id |
Example request:
```sh
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" 'https://gitlab.example.com/api/v4/projects/42/pipeline_schedules/1/play
```
Example response:
```json
{
"message": "201 Created"
}
```
## Pipeline schedule variables ## Pipeline schedule variables
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/issues/34518) in GitLab 10.0. > [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/issues/34518) in GitLab 10.0.
......
...@@ -111,6 +111,25 @@ module API ...@@ -111,6 +111,25 @@ module API
destroy_conditionally!(pipeline_schedule) destroy_conditionally!(pipeline_schedule)
end end
desc 'Play a scheduled pipeline immediately' do
detail 'This feature was added in GitLab 12.8'
end
params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end
post ':id/pipeline_schedules/:pipeline_schedule_id/play' do
authorize! :play_pipeline_schedule, pipeline_schedule
job_id = RunPipelineScheduleWorker
.perform_async(pipeline_schedule.id, current_user.id)
if job_id
created!
else
render_api_error!('Unable to schedule pipeline run immediately', 500)
end
end
desc 'Create a new pipeline schedule variable' do desc 'Create a new pipeline schedule variable' do
success Entities::Variable success Entities::Variable
end end
......
...@@ -322,6 +322,56 @@ describe API::PipelineSchedules do ...@@ -322,6 +322,56 @@ describe API::PipelineSchedules do
end end
end end
describe 'POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play' do
let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
let(:route) { ->(id) { "/projects/#{project.id}/pipeline_schedules/#{id}/play" } }
context 'authenticated user with `:play_pipeline_schedule` permission' do
it 'schedules a pipeline worker' do
project.add_developer(developer)
expect(RunPipelineScheduleWorker)
.to receive(:perform_async)
.with(pipeline_schedule.id, developer.id)
.and_call_original
post api(route[pipeline_schedule.id], developer)
expect(response).to have_gitlab_http_status(:created)
end
it 'renders an error if scheduling failed' do
project.add_developer(developer)
expect(RunPipelineScheduleWorker)
.to receive(:perform_async)
.with(pipeline_schedule.id, developer.id)
.and_return(nil)
post api(route[pipeline_schedule.id], developer)
expect(response).to have_gitlab_http_status(:internal_server_error)
end
end
context 'authenticated user with insufficient access' do
it 'responds with not found' do
project.add_guest(user)
post api(route[pipeline_schedule.id], user)
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'unauthenticated user' do
it 'responds with unauthorized' do
post api(route[pipeline_schedule.id])
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
end
describe 'POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables' do describe 'POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables' do
let(:params) { attributes_for(:ci_pipeline_schedule_variable) } let(:params) { attributes_for(:ci_pipeline_schedule_variable) }
......
Markdown is supported
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