Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-05-24 22:57:58 +0300
committerLin Jen-Shin <godfat@godfat.org>2017-05-25 00:56:58 +0300
commitcafe62b84a9c806535d604ff21c76548b6b06b68 (patch)
tree601410d1f766b935bdd77dc1a94e112c876d42ba
parentc013d23d6320487cf293891f7c6b213cab816980 (diff)
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.
-rw-r--r--app/models/ci/build.rb37
-rw-r--r--db/migrate/20170524195203_add_environment_url_to_ci_builds.rb9
-rw-r--r--db/schema.rb3
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb1
-rw-r--r--lib/gitlab/ci/config/entry/job.rb1
5 files changed, 40 insertions, 11 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 760ec8e5919..82c7ca943ed 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 00000000000..191e7768693
--- /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 84e25427d7f..4c1fd0ec30b 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 b06474cda7f..d49c6c05b50 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 176301bcca1..0891d6ac8bf 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,