diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 760ec8e5919f07b2a8bf2edf60e0a4019a0f074a..82c7ca943ed5b9e066e6256346ccbef90cd73fcc 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -26,6 +26,10 @@ module Ci validates :coverage, numericality: true, allow_blank: true validates :ref, presence: true + validates :environment_url, + length: { maximum: 255 }, + allow_nil: true, + addressable_url: true scope :unstarted, ->() { where(runner_id: nil) } scope :ignore_failures, ->() { where(allow_failure: false) } @@ -132,6 +136,11 @@ module Ci ExpandVariables.expand(environment, simple_variables) if environment end + def expanded_environment_url + ExpandVariables.expand(environment_url, simple_variables) if + environment_url + end + def has_environment? environment.present? end @@ -178,22 +187,23 @@ module Ci # Variables whose value does not depend on other variables def simple_variables variables = predefined_variables - variables += project.predefined_variables - variables += pipeline.predefined_variables - variables += runner.predefined_variables if runner - variables += project.container_registry_variables - variables += project.deployment_variables if has_environment? - variables += yaml_variables - variables += user_variables - variables += project.secret_variables - variables += trigger_request.user_variables if trigger_request + variables.concat(project.predefined_variables) + variables.concat(pipeline.predefined_variables) + variables.concat(runner.predefined_variables) if runner + variables.concat(project.container_registry_variables) + variables.concat(project.deployment_variables) if has_environment? + variables.concat(yaml_variables) + variables.concat(user_variables) + variables.concat(project.secret_variables) + variables.concat(trigger_request.user_variables) if trigger_request variables end # All variables, including those dependent on other variables def variables variables = simple_variables - variables += persisted_environment.predefined_variables if persisted_environment.present? + variables.concat(persisted_environment_variables) if + persisted_environment variables end @@ -488,6 +498,13 @@ module Ci variables.concat(legacy_variables) end + def persisted_environment_variables + persisted_environment.predefined_variables << + { key: 'CI_ENVIRONMENT_URL', + value: expanded_environment_url, + public: true } + end + def legacy_variables variables = [ { key: 'CI_BUILD_ID', value: id.to_s, public: true }, diff --git a/db/migrate/20170524195203_add_environment_url_to_ci_builds.rb b/db/migrate/20170524195203_add_environment_url_to_ci_builds.rb new file mode 100644 index 0000000000000000000000000000000000000000..191e7768693f11c122a150d851b0565947a76e2e --- /dev/null +++ b/db/migrate/20170524195203_add_environment_url_to_ci_builds.rb @@ -0,0 +1,9 @@ +class AddEnvironmentUrlToCiBuilds < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column(:ci_builds, :environment_url, :string) + end +end diff --git a/db/schema.rb b/db/schema.rb index 84e25427d7f81c85716773b76ef1794541977aa6..4c1fd0ec30bc4713bf0ef1aae0176e4343dac0ff 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170521184006) do +ActiveRecord::Schema.define(version: 20170524195203) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -233,6 +233,7 @@ ActiveRecord::Schema.define(version: 20170521184006) do t.string "coverage_regex" t.integer "auto_canceled_by_id" t.boolean "retried" + t.string "environment_url" end add_index "ci_builds", ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index b06474cda7fe308fbfc0dd7c2f4e4a7724774967..d49c6c05b503487f25c03b5c4d7d3a60b57f3afe 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -61,6 +61,7 @@ module Ci allow_failure: job[:ignore], when: job[:when] || 'on_success', environment: job[:environment_name], + environment_url: job[:environment_url], coverage_regex: job[:coverage], yaml_variables: yaml_variables(name), options: { diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 176301bcca1bf98e1dedeecffad18ef2139de311..0891d6ac8bfb76578ea668941320157ae71dc949 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -141,6 +141,7 @@ module Gitlab variables: variables_defined? ? variables_value : nil, environment: environment_defined? ? environment_value : nil, environment_name: environment_defined? ? environment_value[:name] : nil, + environment_url: environment_defined? ? environment_value[:url] : nil, coverage: coverage_defined? ? coverage_value : nil, artifacts: artifacts_value, after_script: after_script_value,