diff options
Diffstat (limited to 'app/services/deployments/create_for_build_service.rb')
-rw-r--r-- | app/services/deployments/create_for_build_service.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/services/deployments/create_for_build_service.rb b/app/services/deployments/create_for_build_service.rb new file mode 100644 index 00000000000..b3e2d2edb59 --- /dev/null +++ b/app/services/deployments/create_for_build_service.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Deployments + # This class creates a deployment record for a build (a pipeline job). + class CreateForBuildService + DeploymentCreationError = Class.new(StandardError) + + def execute(build) + return unless build.instance_of?(::Ci::Build) && build.persisted_environment.present? + + # TODO: Move all buisness logic in `Seed::Deployment` to this class after + # `create_deployment_in_separate_transaction` feature flag has been removed. + # See https://gitlab.com/gitlab-org/gitlab/-/issues/348778 + deployment = ::Gitlab::Ci::Pipeline::Seed::Deployment + .new(build, build.persisted_environment).to_resource + + return unless deployment + + build.create_deployment!(deployment.attributes) + rescue ActiveRecord::RecordInvalid => e + Gitlab::ErrorTracking.track_and_raise_for_dev_exception( + DeploymentCreationError.new(e.message), build_id: build.id) + end + end +end |