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
belongs_to :trigger_request
belongs_to :erased_by, class_name: 'User'
has_many :deployments, as: :deployable
serialize :options
serialize :yaml_variables
......@@ -125,10 +127,12 @@ module Ci
!self.pipeline.statuses.latest.include?(self)
end
def last_deployment
return @last_deployment if defined?(@last_deployment)
def deployable?
self.environment.present?
end
@last_deployment = Deployment.where(deployable: self).order(id: :desc).last
def last_deployment
deployments.order(id: :desc).last
end
def depends_on_builds
......
......@@ -26,28 +26,30 @@
= link_to namespace_project_runners_path(@build.project.namespace, @build.project) do
Runners page
- if @build.deploy
- if @build.deployable?
.prepend-top-default
.environment-information
= ci_icon_for_status(@build.status)
- if @build.last_deployment
- last_deployment = @build.last_deployment
- if @build.complete?
- if @build.success?
- if last_deployment.try(:last?)
This build is the most recent deployment to
= link_to @build.environment, namespace_project_environment_path(@project.namespace, @project, @build.environment)
= 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
- case @build.status
- when 'failed', 'canceled'
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
- when 'pending', 'running'
- else
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
- 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
- if @build.erased?
......
......@@ -4,15 +4,13 @@ class BuildSuccessWorker
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
create_deployment(build)
create_deployment(build) if build.deployable?
end
end
private
def create_deployment(build)
return if build.environment.blank?
service = CreateDeploymentService.new(
build.project, build.user,
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