Implement $CI_ENVIRONMENT_URL for jobs
We introduce ci_builds.environment_url and expand it when passing to runners. In the future the deployment could also retrieve the URL from the job instead of from the environment, which might have a different external URL because of another deployment happened.
This commit is contained in:
parent
c013d23d63
commit
cafe62b84a
|
@ -26,6 +26,10 @@ module Ci
|
||||||
|
|
||||||
validates :coverage, numericality: true, allow_blank: true
|
validates :coverage, numericality: true, allow_blank: true
|
||||||
validates :ref, presence: true
|
validates :ref, presence: true
|
||||||
|
validates :environment_url,
|
||||||
|
length: { maximum: 255 },
|
||||||
|
allow_nil: true,
|
||||||
|
addressable_url: true
|
||||||
|
|
||||||
scope :unstarted, ->() { where(runner_id: nil) }
|
scope :unstarted, ->() { where(runner_id: nil) }
|
||||||
scope :ignore_failures, ->() { where(allow_failure: false) }
|
scope :ignore_failures, ->() { where(allow_failure: false) }
|
||||||
|
@ -132,6 +136,11 @@ module Ci
|
||||||
ExpandVariables.expand(environment, simple_variables) if environment
|
ExpandVariables.expand(environment, simple_variables) if environment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expanded_environment_url
|
||||||
|
ExpandVariables.expand(environment_url, simple_variables) if
|
||||||
|
environment_url
|
||||||
|
end
|
||||||
|
|
||||||
def has_environment?
|
def has_environment?
|
||||||
environment.present?
|
environment.present?
|
||||||
end
|
end
|
||||||
|
@ -178,22 +187,23 @@ module Ci
|
||||||
# Variables whose value does not depend on other variables
|
# Variables whose value does not depend on other variables
|
||||||
def simple_variables
|
def simple_variables
|
||||||
variables = predefined_variables
|
variables = predefined_variables
|
||||||
variables += project.predefined_variables
|
variables.concat(project.predefined_variables)
|
||||||
variables += pipeline.predefined_variables
|
variables.concat(pipeline.predefined_variables)
|
||||||
variables += runner.predefined_variables if runner
|
variables.concat(runner.predefined_variables) if runner
|
||||||
variables += project.container_registry_variables
|
variables.concat(project.container_registry_variables)
|
||||||
variables += project.deployment_variables if has_environment?
|
variables.concat(project.deployment_variables) if has_environment?
|
||||||
variables += yaml_variables
|
variables.concat(yaml_variables)
|
||||||
variables += user_variables
|
variables.concat(user_variables)
|
||||||
variables += project.secret_variables
|
variables.concat(project.secret_variables)
|
||||||
variables += trigger_request.user_variables if trigger_request
|
variables.concat(trigger_request.user_variables) if trigger_request
|
||||||
variables
|
variables
|
||||||
end
|
end
|
||||||
|
|
||||||
# All variables, including those dependent on other variables
|
# All variables, including those dependent on other variables
|
||||||
def variables
|
def variables
|
||||||
variables = simple_variables
|
variables = simple_variables
|
||||||
variables += persisted_environment.predefined_variables if persisted_environment.present?
|
variables.concat(persisted_environment_variables) if
|
||||||
|
persisted_environment
|
||||||
variables
|
variables
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -488,6 +498,13 @@ module Ci
|
||||||
variables.concat(legacy_variables)
|
variables.concat(legacy_variables)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def persisted_environment_variables
|
||||||
|
persisted_environment.predefined_variables <<
|
||||||
|
{ key: 'CI_ENVIRONMENT_URL',
|
||||||
|
value: expanded_environment_url,
|
||||||
|
public: true }
|
||||||
|
end
|
||||||
|
|
||||||
def legacy_variables
|
def legacy_variables
|
||||||
variables = [
|
variables = [
|
||||||
{ key: 'CI_BUILD_ID', value: id.to_s, public: true },
|
{ key: 'CI_BUILD_ID', value: id.to_s, public: true },
|
||||||
|
|
|
@ -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
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -233,6 +233,7 @@ ActiveRecord::Schema.define(version: 20170521184006) do
|
||||||
t.string "coverage_regex"
|
t.string "coverage_regex"
|
||||||
t.integer "auto_canceled_by_id"
|
t.integer "auto_canceled_by_id"
|
||||||
t.boolean "retried"
|
t.boolean "retried"
|
||||||
|
t.string "environment_url"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "ci_builds", ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree
|
add_index "ci_builds", ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree
|
||||||
|
|
|
@ -61,6 +61,7 @@ module Ci
|
||||||
allow_failure: job[:ignore],
|
allow_failure: job[:ignore],
|
||||||
when: job[:when] || 'on_success',
|
when: job[:when] || 'on_success',
|
||||||
environment: job[:environment_name],
|
environment: job[:environment_name],
|
||||||
|
environment_url: job[:environment_url],
|
||||||
coverage_regex: job[:coverage],
|
coverage_regex: job[:coverage],
|
||||||
yaml_variables: yaml_variables(name),
|
yaml_variables: yaml_variables(name),
|
||||||
options: {
|
options: {
|
||||||
|
|
|
@ -141,6 +141,7 @@ module Gitlab
|
||||||
variables: variables_defined? ? variables_value : nil,
|
variables: variables_defined? ? variables_value : nil,
|
||||||
environment: environment_defined? ? environment_value : nil,
|
environment: environment_defined? ? environment_value : nil,
|
||||||
environment_name: environment_defined? ? environment_value[:name] : nil,
|
environment_name: environment_defined? ? environment_value[:name] : nil,
|
||||||
|
environment_url: environment_defined? ? environment_value[:url] : nil,
|
||||||
coverage: coverage_defined? ? coverage_value : nil,
|
coverage: coverage_defined? ? coverage_value : nil,
|
||||||
artifacts: artifacts_value,
|
artifacts: artifacts_value,
|
||||||
after_script: after_script_value,
|
after_script: after_script_value,
|
||||||
|
|
Loading…
Reference in New Issue