From 88d1ec62fe60b21d86e87a0b4300c98dc36add62 Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Tue, 29 Jan 2019 16:47:25 +0000 Subject: [PATCH] Add GitLab Pages predefined variables --- app/models/project.rb | 8 ++++++++ .../adrianmoisey-GITLAB_PAGES_PREDEFINED_VARIABLES.yml | 5 +++++ doc/ci/variables/README.md | 8 ++++++++ spec/models/ci/build_spec.rb | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 changelogs/unreleased/adrianmoisey-GITLAB_PAGES_PREDEFINED_VARIABLES.yml diff --git a/app/models/project.rb b/app/models/project.rb index 15465d9b356..b509120ff83 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1689,11 +1689,19 @@ class Project < ActiveRecord::Base .append(key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path) .append(key: 'CI_PROJECT_URL', value: web_url) .append(key: 'CI_PROJECT_VISIBILITY', value: visibility) + .concat(pages_variables) .concat(container_registry_variables) .concat(auto_devops_variables) .concat(api_variables) end + def pages_variables + Gitlab::Ci::Variables::Collection.new.tap do |variables| + variables.append(key: 'CI_PAGES_DOMAIN', value: Gitlab.config.pages.host) + variables.append(key: 'CI_PAGES_URL', value: pages_url) + end + end + def api_variables Gitlab::Ci::Variables::Collection.new.tap do |variables| variables.append(key: 'CI_API_V4_URL', value: API::Helpers::Version.new('v4').root_url) diff --git a/changelogs/unreleased/adrianmoisey-GITLAB_PAGES_PREDEFINED_VARIABLES.yml b/changelogs/unreleased/adrianmoisey-GITLAB_PAGES_PREDEFINED_VARIABLES.yml new file mode 100644 index 00000000000..a664c44e1d7 --- /dev/null +++ b/changelogs/unreleased/adrianmoisey-GITLAB_PAGES_PREDEFINED_VARIABLES.yml @@ -0,0 +1,5 @@ +--- +title: Add GitLab Pages predefined CI variables 'CI_PAGES_DOMAIN' and 'CI_PAGES_URL' +merge_request: 24504 +author: Adrian Moisey +type: added diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md index 5195c580734..ac46e0eedc6 100644 --- a/doc/ci/variables/README.md +++ b/doc/ci/variables/README.md @@ -85,6 +85,8 @@ future GitLab releases.** | **CI_NODE_INDEX** | 11.5 | all | Index of the job in the job set. If the job is not parallelized, this variable is not set. | | **CI_NODE_TOTAL** | 11.5 | all | Total number of instances of this job running in parallel. If the job is not parallelized, this variable is set to `1`. | | **CI_API_V4_URL** | 11.7 | all | The GitLab API v4 root URL | +| **CI_PAGES_DOMAIN** | 11.8 | all | The configured domain that hosts GitLab Pages. | +| **CI_PAGES_URL** | 11.8 | all | URL to GitLab Pages-built pages. Always belongs to a subdomain of `CI_PAGES_DOMAIN`. | | **CI_PIPELINE_ID** | 8.10 | all | The unique id of the current pipeline that GitLab CI uses internally | | **CI_PIPELINE_IID** | 11.0 | all | The unique id of the current pipeline scoped to project | | **CI_PIPELINE_SOURCE** | 10.0 | all | Indicates how the pipeline was triggered. Possible options are: `push`, `web`, `trigger`, `schedule`, `api`, and `pipeline`. For pipelines created before GitLab 9.5, this will show as `unknown` | @@ -395,6 +397,10 @@ Running on runner-8a2f473d-project-1796893-concurrent-0 via runner-8a2f473d-mach ++ CI_SERVER_VERSION=8.14.3-ee ++ export CI_SERVER_REVISION=82823 ++ CI_SERVER_REVISION=82823 +++ export CI_PAGES_DOMAIN=gitlab.io +++ CI_PAGES_DOMAIN=gitlab.io +++ export CI_PAGES_URL=https://gitlab-examples.gitlab.io/ci-debug-trace +++ CI_PAGES_URL=https://gitlab-examples.gitlab.io/ci-debug-trace ++ export CI_PROJECT_ID=17893 ++ CI_PROJECT_ID=17893 ++ export CI_PROJECT_NAME=ci-debug-trace @@ -498,6 +504,8 @@ export CI_JOB_TRIGGERED="true" export CI_JOB_TOKEN="abcde-1234ABCD5678ef" export CI_PIPELINE_ID="1000" export CI_PIPELINE_IID="10" +export CI_PAGES_DOMAIN="gitlab.io" +export CI_PAGES_URL="https://gitlab-org.gitlab.io/gitlab-ce" export CI_PROJECT_ID="34" export CI_PROJECT_DIR="/builds/gitlab-org/gitlab-ce" export CI_PROJECT_NAME="gitlab-ce" diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 8ba33ff9c04..8a1bbb26e57 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2133,6 +2133,8 @@ describe Ci::Build do { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true }, { key: 'CI_PROJECT_URL', value: project.web_url, public: true }, { key: 'CI_PROJECT_VISIBILITY', value: 'private', public: true }, + { key: 'CI_PAGES_DOMAIN', value: Gitlab.config.pages.host, public: true }, + { key: 'CI_PAGES_URL', value: project.pages_url, public: true }, { key: 'CI_API_V4_URL', value: 'http://localhost/api/v4', public: true }, { key: 'CI_PIPELINE_IID', value: pipeline.iid.to_s, public: true }, { key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, public: true },