Commit c70acb57 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Annabel Dunstone Gray

Expose `last_deployment` on `Ci::Builds` [ci skip]

parent 73467bd1
module EnvironmentHelper
def environment_for_build(project, build)
return unless build.environment
environment_name = ExpandVariables.expand(build.environment, build.variables)
project.environments.find_by(name: environment_name)
end
def environment_link_for_build(project, build)
environment = environment_for_build(project, build)
return unless environment
link_to environment.name, namespace_project_environment_path(project.namespace, project, environment)
end
def deployment_link(project, deployment)
return unless deployment
link_to "##{deployment.id}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable]
end
end
...@@ -7,6 +7,8 @@ module Ci ...@@ -7,6 +7,8 @@ module Ci
belongs_to :trigger_request belongs_to :trigger_request
belongs_to :erased_by, class_name: 'User' belongs_to :erased_by, class_name: 'User'
has_many :deployments, as: :deployable
serialize :options serialize :options
serialize :yaml_variables serialize :yaml_variables
...@@ -125,10 +127,12 @@ module Ci ...@@ -125,10 +127,12 @@ module Ci
!self.pipeline.statuses.latest.include?(self) !self.pipeline.statuses.latest.include?(self)
end end
def last_deployment def deployable?
return @last_deployment if defined?(@last_deployment) self.environment.present?
end
@last_deployment = Deployment.where(deployable: self).order(id: :desc).last def last_deployment
deployments.order(id: :desc).last
end end
def depends_on_builds def depends_on_builds
......
...@@ -26,28 +26,30 @@ ...@@ -26,28 +26,30 @@
= link_to namespace_project_runners_path(@build.project.namespace, @build.project) do = link_to namespace_project_runners_path(@build.project.namespace, @build.project) do
Runners page Runners page
- if @build.deploy - if @build.deployable?
.prepend-top-default .prepend-top-default
.environment-information .environment-information
= ci_icon_for_status(@build.status) = ci_icon_for_status(@build.status)
- if @build.last_deployment - last_deployment = @build.last_deployment
This build is the most recent deployment to - if @build.complete?
= link_to @build.environment, namespace_project_environment_path(@project.namespace, @project, @build.environment) - if @build.success?
- else - if last_deployment.try(:last?)
- case @build.status This build is the most recent deployment to
- when 'failed', 'canceled' = environment_link_for_build(@build.project, @build)
- else
This build is an out-of-date deployment to
= environment_link_for_build(@build.project, @build)
View the most recent deployment
= deployment_link(@project, last_deployment)
- else
The deployment of this build to The deployment of this build to
= link_to @build.environment, namespace_project_environment_path(@project.namespace, @project, @build.environment) = environment_link_for_build(@build.project, @build)
did not complete did not complete
- when 'pending', 'running' - else
This build is creating a deployment to This build is creating a deployment to
= link_to @build.environment, namespace_project_environment_path(@project.namespace, @project, @build.environment) = environment_link_for_build(@build.project, @build)
and will overwrite the latest deployment and will overwrite the latest deployment
- when 'success'
This build is an out-of-date deployment to
= link_to @build.environment, namespace_project_environment_path(@project.namespace, @project, @build.environment)
View the most recent deployment #24869
.prepend-top-default .prepend-top-default
- if @build.erased? - if @build.erased?
......
...@@ -4,15 +4,13 @@ class BuildSuccessWorker ...@@ -4,15 +4,13 @@ class BuildSuccessWorker
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by(id: build_id).try do |build|
create_deployment(build) create_deployment(build) if build.deployable?
end end
end end
private private
def create_deployment(build) def create_deployment(build)
return if build.environment.blank?
service = CreateDeploymentService.new( service = CreateDeploymentService.new(
build.project, build.user, build.project, build.user,
environment: build.environment, environment: build.environment,
......
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