BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8e7f19c6
Commit
8e7f19c6
authored
Dec 02, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add button to run scheduled pipeline immediately
Closes #38741
parent
ad1ce123
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
3 deletions
+110
-3
pipeline_schedules_controller.rb
app/controllers/projects/pipeline_schedules_controller.rb
+15
-1
gitlab_routing_helper.rb
app/helpers/gitlab_routing_helper.rb
+5
-0
_pipeline_schedule.html.haml
.../projects/pipeline_schedules/_pipeline_schedule.html.haml
+3
-1
run_pipeline_schedule_worker.rb
app/workers/run_pipeline_schedule_worker.rb
+20
-0
sh-add-schedule-pipeline-run-now.yml
changelogs/unreleased/sh-add-schedule-pipeline-run-now.yml
+5
-0
project.rb
config/routes/project.rb
+1
-0
pipeline_schedules_controller_spec.rb
...ontrollers/projects/pipeline_schedules_controller_spec.rb
+25
-1
run_pipeline_schedule_worker_spec.rb
spec/workers/run_pipeline_schedule_worker_spec.rb
+36
-0
No files found.
app/controllers/projects/pipeline_schedules_controller.rb
View file @
8e7f19c6
class
Projects
::
PipelineSchedulesController
<
Projects
::
ApplicationController
before_action
:schedule
,
except:
[
:index
,
:new
,
:create
]
before_action
:authorize_create_pipeline!
,
only:
[
:run
]
before_action
:authorize_read_pipeline_schedule!
before_action
:authorize_create_pipeline_schedule!
,
only:
[
:new
,
:create
]
before_action
:authorize_update_pipeline_schedule!
,
except:
[
:index
,
:new
,
:create
]
before_action
:authorize_update_pipeline_schedule!
,
except:
[
:index
,
:new
,
:create
,
:run
]
before_action
:authorize_admin_pipeline_schedule!
,
only:
[
:destroy
]
def
index
...
...
@@ -40,6 +41,19 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
end
end
def
run
job_id
=
RunPipelineScheduleWorker
.
perform_async
(
schedule
.
id
,
current_user
.
id
)
flash
[
:notice
]
=
if
job_id
'Successfully scheduled pipeline to run immediately'
else
'Unable to schedule a pipeline to run immediately'
end
redirect_to
pipeline_schedules_path
(
@project
)
end
def
take_ownership
if
schedule
.
update
(
owner:
current_user
)
redirect_to
pipeline_schedules_path
(
@project
)
...
...
app/helpers/gitlab_routing_helper.rb
View file @
8e7f19c6
...
...
@@ -182,6 +182,11 @@ module GitlabRoutingHelper
edit_project_pipeline_schedule_path
(
project
,
schedule
)
end
def
run_pipeline_schedule_path
(
schedule
,
*
args
)
project
=
schedule
.
project
run_project_pipeline_schedule_path
(
project
,
schedule
,
*
args
)
end
def
take_ownership_pipeline_schedule_path
(
schedule
,
*
args
)
project
=
schedule
.
project
take_ownership_project_pipeline_schedule_path
(
project
,
schedule
,
*
args
)
...
...
app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml
View file @
8e7f19c6
...
...
@@ -26,10 +26,12 @@
=
pipeline_schedule
.
owner
&
.
name
%td
.pull-right.btn-group
-
if
can?
(
current_user
,
:create_pipeline
,
@project
)
=
link_to
run_pipeline_schedule_path
(
pipeline_schedule
),
method: :post
,
title:
s_
(
'Play'
),
class:
'btn'
do
=
icon
(
'play'
)
-
if
can?
(
current_user
,
:update_pipeline_schedule
,
pipeline_schedule
)
=
link_to
take_ownership_pipeline_schedule_path
(
pipeline_schedule
),
method: :post
,
title:
s_
(
'PipelineSchedules|Take ownership'
),
class:
'btn'
do
=
s_
(
'PipelineSchedules|Take ownership'
)
-
if
can?
(
current_user
,
:update_pipeline_schedule
,
pipeline_schedule
)
=
link_to
edit_pipeline_schedule_path
(
pipeline_schedule
),
title:
_
(
'Edit'
),
class:
'btn'
do
=
icon
(
'pencil'
)
-
if
can?
(
current_user
,
:admin_pipeline_schedule
,
pipeline_schedule
)
...
...
app/workers/run_pipeline_schedule_worker.rb
0 → 100644
View file @
8e7f19c6
class
RunPipelineScheduleWorker
include
Sidekiq
::
Worker
include
PipelineQueue
enqueue_in
group: :creation
def
perform
(
schedule_id
,
user_id
)
schedule
=
Ci
::
PipelineSchedule
.
find
(
schedule_id
)
user
=
User
.
find
(
user_id
)
run_pipeline_schedule
(
schedule
,
user
)
end
def
run_pipeline_schedule
(
schedule
,
user
)
Ci
::
CreatePipelineService
.
new
(
schedule
.
project
,
user
,
ref:
schedule
.
ref
)
.
execute
(
:schedule
,
ignore_skip_ci:
true
,
save_on_errors:
false
,
schedule:
schedule
)
end
end
changelogs/unreleased/sh-add-schedule-pipeline-run-now.yml
0 → 100644
View file @
8e7f19c6
---
title
:
Add button to run scheduled pipeline immediately
merge_request
:
author
:
type
:
added
config/routes/project.rb
View file @
8e7f19c6
...
...
@@ -179,6 +179,7 @@ constraints(ProjectUrlConstrainer.new) do
resources
:pipeline_schedules
,
except:
[
:show
]
do
member
do
post
:run
post
:take_ownership
end
end
...
...
spec/controllers/projects/pipeline_schedules_controller_spec.rb
View file @
8e7f19c6
...
...
@@ -96,7 +96,7 @@ describe Projects::PipelineSchedulesController do
end
end
context
'when variables_attributes has two variables and duplicted'
do
context
'when variables_attributes has two variables and duplic
a
ted'
do
let
(
:schedule
)
do
basic_param
.
merge
({
variables_attributes:
[{
key:
'AAA'
,
value:
'AAA123'
},
{
key:
'AAA'
,
value:
'BBB123'
}]
...
...
@@ -364,6 +364,30 @@ describe Projects::PipelineSchedulesController do
end
end
describe
'POST #run'
do
set
(
:user
)
{
create
(
:user
)
}
context
'when a developer makes the request'
do
before
do
project
.
add_developer
(
user
)
sign_in
(
user
)
end
it
'executes a new pipeline'
do
expect
(
RunPipelineScheduleWorker
).
to
receive
(
:perform_async
).
with
(
pipeline_schedule
.
id
,
user
.
id
).
and_return
(
'job-123'
)
go
expect
(
flash
[
:notice
]).
to
eq
'Successfully scheduled pipeline to run immediately'
expect
(
response
).
to
have_gitlab_http_status
(
302
)
end
end
def
go
post
:run
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
id:
pipeline_schedule
.
id
end
end
describe
'DELETE #destroy'
do
set
(
:user
)
{
create
(
:user
)
}
...
...
spec/workers/run_pipeline_schedule_worker_spec.rb
0 → 100644
View file @
8e7f19c6
require
'spec_helper'
describe
RunPipelineScheduleWorker
do
describe
'#perform'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:worker
)
{
described_class
.
new
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline_schedule
)
{
create
(
:ci_pipeline_schedule
,
:nightly
,
project:
project
)
}
context
'when a project not found'
do
it
'does not call the Service'
do
expect
(
Ci
::
CreatePipelineService
).
not_to
receive
(
:new
)
expect
{
worker
.
perform
(
100000
,
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
context
'when a user not found'
do
it
'does not call the Service'
do
expect
(
Ci
::
CreatePipelineService
).
not_to
receive
(
:new
)
expect
{
worker
.
perform
(
pipeline_schedule
.
id
,
10000
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
context
'when everything is ok'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:create_pipeline_service
)
{
instance_double
(
Ci
::
CreatePipelineService
)
}
it
'calls the Service'
do
expect
(
Ci
::
CreatePipelineService
).
to
receive
(
:new
).
with
(
project
,
user
,
ref:
pipeline_schedule
.
ref
).
and_return
(
create_pipeline_service
)
expect
(
create_pipeline_service
).
to
receive
(
:execute
).
with
(
:schedule
,
ignore_skip_ci:
true
,
save_on_errors:
false
,
schedule:
pipeline_schedule
)
worker
.
perform
(
pipeline_schedule
.
id
,
user
.
id
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment