From af46d33fba477785dfbe5af2d38a2e4f0ed0b696 Mon Sep 17 00:00:00 2001 From: Jason van den Hurk Date: Thu, 28 Mar 2019 13:53:35 +0100 Subject: Added the CI_REF_PROTECTED variable to the Gitlab runner This variable shows if the branch the runner is executing is protected or not. References: #50909 --- app/models/ci/pipeline.rb | 1 + spec/models/ci/bridge_spec.rb | 2 +- spec/models/ci/build_spec.rb | 3 ++- spec/models/ci/pipeline_spec.rb | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index b81a3cf8362..9e382d483f1 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -638,6 +638,7 @@ module Ci variables.append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message.to_s) variables.append(key: 'CI_COMMIT_TITLE', value: git_commit_full_title.to_s) variables.append(key: 'CI_COMMIT_DESCRIPTION', value: git_commit_description.to_s) + variables.append(key: 'CI_REF_PROTECTED', value: protected_ref?.to_s) if merge_request_event? && merge_request variables.append(key: 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA', value: source_sha.to_s) diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb index aacfbe3f180..fce53a96857 100644 --- a/spec/models/ci/bridge_spec.rb +++ b/spec/models/ci/bridge_spec.rb @@ -33,7 +33,7 @@ describe Ci::Bridge do CI_PROJECT_ID CI_PROJECT_NAME CI_PROJECT_PATH CI_PROJECT_PATH_SLUG CI_PROJECT_NAMESPACE CI_PIPELINE_IID CI_CONFIG_PATH CI_PIPELINE_SOURCE CI_COMMIT_MESSAGE - CI_COMMIT_TITLE CI_COMMIT_DESCRIPTION + CI_COMMIT_TITLE CI_COMMIT_DESCRIPTION CI_REF_PROTECTED ] expect(bridge.scoped_variables_hash.keys).to include(*variables) diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 1352a2de2d7..4c717357bd0 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2227,7 +2227,8 @@ describe Ci::Build do { key: 'CI_PIPELINE_SOURCE', value: pipeline.source, public: true, masked: false }, { key: 'CI_COMMIT_MESSAGE', value: pipeline.git_commit_message, public: true, masked: false }, { key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false }, - { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false } + { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false }, + { key: 'CI_REF_PROTECTED', value: pipeline.protected_ref?.to_s, public: true, masked: false } ] end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index f3e78630c1b..9b86fbbefe8 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -670,7 +670,8 @@ describe Ci::Pipeline, :mailer do CI_PIPELINE_SOURCE CI_COMMIT_MESSAGE CI_COMMIT_TITLE - CI_COMMIT_DESCRIPTION] + CI_COMMIT_DESCRIPTION + CI_REF_PROTECTED] end context 'when source is merge request' do -- cgit v1.2.1 From 22cd71a66391605f67245f816d309a812ec56851 Mon Sep 17 00:00:00 2001 From: Jason van den Hurk Date: Thu, 28 Mar 2019 13:58:39 +0100 Subject: Added documentation for CI_REF_PROTECTED ci variable --- doc/ci/variables/predefined_variables.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ci/variables/predefined_variables.md b/doc/ci/variables/predefined_variables.md index 846c539daab..74c34807b19 100644 --- a/doc/ci/variables/predefined_variables.md +++ b/doc/ci/variables/predefined_variables.md @@ -84,6 +84,7 @@ future GitLab releases.** | `CI_PROJECT_PATH_SLUG` | 9.3 | all | `$CI_PROJECT_PATH` lowercased and with everything except `0-9` and `a-z` replaced with `-`. Use in URLs and domain names. | | `CI_PROJECT_URL` | 8.10 | 0.5 | The HTTP(S) address to access project | | `CI_PROJECT_VISIBILITY` | 10.3 | all | The project visibility (internal, private, public) | +| `CI_REF_PROTECTED` | 11.10 | all | If the job is running on a protected branch | | `CI_REGISTRY` | 8.10 | 0.5 | If the Container Registry is enabled it returns the address of GitLab's Container Registry | | `CI_REGISTRY_IMAGE` | 8.10 | 0.5 | If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project | | `CI_REGISTRY_PASSWORD` | 9.0 | all | The password to use to push containers to the GitLab Container Registry | -- cgit v1.2.1 From 10cebe85ae963cd9a00b3f7b882ae389f5a57b35 Mon Sep 17 00:00:00 2001 From: Jason van den Hurk Date: Thu, 28 Mar 2019 14:08:16 +0100 Subject: Add changelog entry --- changelogs/unreleased/add-ci-variable-protected-ref.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/add-ci-variable-protected-ref.yml diff --git a/changelogs/unreleased/add-ci-variable-protected-ref.yml b/changelogs/unreleased/add-ci-variable-protected-ref.yml new file mode 100644 index 00000000000..9e44232fdff --- /dev/null +++ b/changelogs/unreleased/add-ci-variable-protected-ref.yml @@ -0,0 +1,5 @@ +--- +title: Add CI_REF_PROTECTED CI variable +merge_request: 26716 +author: Jason van den Hurk +type: added -- cgit v1.2.1 From cd0eaccbfe59b7ac1e63aa59658ced2dc2ea27df Mon Sep 17 00:00:00 2001 From: Jason van den Hurk Date: Wed, 10 Apr 2019 09:06:00 +0000 Subject: Change release version of CI_REF_PROTECTED to 11.11 --- doc/ci/variables/predefined_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ci/variables/predefined_variables.md b/doc/ci/variables/predefined_variables.md index 74c34807b19..1c2908e7e9b 100644 --- a/doc/ci/variables/predefined_variables.md +++ b/doc/ci/variables/predefined_variables.md @@ -84,7 +84,7 @@ future GitLab releases.** | `CI_PROJECT_PATH_SLUG` | 9.3 | all | `$CI_PROJECT_PATH` lowercased and with everything except `0-9` and `a-z` replaced with `-`. Use in URLs and domain names. | | `CI_PROJECT_URL` | 8.10 | 0.5 | The HTTP(S) address to access project | | `CI_PROJECT_VISIBILITY` | 10.3 | all | The project visibility (internal, private, public) | -| `CI_REF_PROTECTED` | 11.10 | all | If the job is running on a protected branch | +| `CI_REF_PROTECTED` | 11.11 | all | If the job is running on a protected branch | | `CI_REGISTRY` | 8.10 | 0.5 | If the Container Registry is enabled it returns the address of GitLab's Container Registry | | `CI_REGISTRY_IMAGE` | 8.10 | 0.5 | If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project | | `CI_REGISTRY_PASSWORD` | 9.0 | all | The password to use to push containers to the GitLab Container Registry | -- cgit v1.2.1 From 8d1649f77460b1203e6497b91342cc08b93ae160 Mon Sep 17 00:00:00 2001 From: Jason van den Hurk Date: Wed, 10 Apr 2019 12:56:56 +0200 Subject: Change CI_REF_PROTECTED variable to CI_COMMIT_REF_PROTECTED --- app/models/ci/pipeline.rb | 2 +- changelogs/unreleased/add-ci-variable-protected-ref.yml | 2 +- doc/ci/variables/predefined_variables.md | 2 +- spec/models/ci/bridge_spec.rb | 2 +- spec/models/ci/build_spec.rb | 2 +- spec/models/ci/pipeline_spec.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 9e382d483f1..7aad4d2c176 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -638,7 +638,7 @@ module Ci variables.append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message.to_s) variables.append(key: 'CI_COMMIT_TITLE', value: git_commit_full_title.to_s) variables.append(key: 'CI_COMMIT_DESCRIPTION', value: git_commit_description.to_s) - variables.append(key: 'CI_REF_PROTECTED', value: protected_ref?.to_s) + variables.append(key: 'CI_COMMIT_REF_PROTECTED', value: protected_ref?.to_s) if merge_request_event? && merge_request variables.append(key: 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA', value: source_sha.to_s) diff --git a/changelogs/unreleased/add-ci-variable-protected-ref.yml b/changelogs/unreleased/add-ci-variable-protected-ref.yml index 9e44232fdff..150ddcc21ad 100644 --- a/changelogs/unreleased/add-ci-variable-protected-ref.yml +++ b/changelogs/unreleased/add-ci-variable-protected-ref.yml @@ -1,5 +1,5 @@ --- -title: Add CI_REF_PROTECTED CI variable +title: Add CI_COMMIT_REF_PROTECTED CI variable merge_request: 26716 author: Jason van den Hurk type: added diff --git a/doc/ci/variables/predefined_variables.md b/doc/ci/variables/predefined_variables.md index 1c2908e7e9b..05bde5ed4c8 100644 --- a/doc/ci/variables/predefined_variables.md +++ b/doc/ci/variables/predefined_variables.md @@ -84,7 +84,7 @@ future GitLab releases.** | `CI_PROJECT_PATH_SLUG` | 9.3 | all | `$CI_PROJECT_PATH` lowercased and with everything except `0-9` and `a-z` replaced with `-`. Use in URLs and domain names. | | `CI_PROJECT_URL` | 8.10 | 0.5 | The HTTP(S) address to access project | | `CI_PROJECT_VISIBILITY` | 10.3 | all | The project visibility (internal, private, public) | -| `CI_REF_PROTECTED` | 11.11 | all | If the job is running on a protected branch | +| `CI_COMMIT_REF_PROTECTED` | 11.11 | all | If the job is running on a protected branch | | `CI_REGISTRY` | 8.10 | 0.5 | If the Container Registry is enabled it returns the address of GitLab's Container Registry | | `CI_REGISTRY_IMAGE` | 8.10 | 0.5 | If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project | | `CI_REGISTRY_PASSWORD` | 9.0 | all | The password to use to push containers to the GitLab Container Registry | diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb index fce53a96857..44b5af5e5aa 100644 --- a/spec/models/ci/bridge_spec.rb +++ b/spec/models/ci/bridge_spec.rb @@ -33,7 +33,7 @@ describe Ci::Bridge do CI_PROJECT_ID CI_PROJECT_NAME CI_PROJECT_PATH CI_PROJECT_PATH_SLUG CI_PROJECT_NAMESPACE CI_PIPELINE_IID CI_CONFIG_PATH CI_PIPELINE_SOURCE CI_COMMIT_MESSAGE - CI_COMMIT_TITLE CI_COMMIT_DESCRIPTION CI_REF_PROTECTED + CI_COMMIT_TITLE CI_COMMIT_DESCRIPTION CI_COMMIT_REF_PROTECTED ] expect(bridge.scoped_variables_hash.keys).to include(*variables) diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 4c717357bd0..7af5237a503 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2228,7 +2228,7 @@ describe Ci::Build do { key: 'CI_COMMIT_MESSAGE', value: pipeline.git_commit_message, public: true, masked: false }, { key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false }, { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false }, - { key: 'CI_REF_PROTECTED', value: pipeline.protected_ref?.to_s, public: true, masked: false } + { key: 'CI_COMMIT_REF_PROTECTED', value: pipeline.protected_ref?.to_s, public: true, masked: false } ] end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 9b86fbbefe8..f3310ff0f82 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -671,7 +671,7 @@ describe Ci::Pipeline, :mailer do CI_COMMIT_MESSAGE CI_COMMIT_TITLE CI_COMMIT_DESCRIPTION - CI_REF_PROTECTED] + CI_COMMIT_REF_PROTECTED] end context 'when source is merge request' do -- cgit v1.2.1 From d1b2056c155f49004a80280e46d7136fd804ad98 Mon Sep 17 00:00:00 2001 From: Jason van den Hurk Date: Thu, 18 Apr 2019 11:34:20 +0200 Subject: Make sure that CI_COMMIT_REF_PROTECTED is a bool --- app/models/ci/pipeline.rb | 2 +- spec/models/ci/build_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 7aad4d2c176..3d6ee675944 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -638,7 +638,7 @@ module Ci variables.append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message.to_s) variables.append(key: 'CI_COMMIT_TITLE', value: git_commit_full_title.to_s) variables.append(key: 'CI_COMMIT_DESCRIPTION', value: git_commit_description.to_s) - variables.append(key: 'CI_COMMIT_REF_PROTECTED', value: protected_ref?.to_s) + variables.append(key: 'CI_COMMIT_REF_PROTECTED', value: (!!protected_ref?).to_s) if merge_request_event? && merge_request variables.append(key: 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA', value: source_sha.to_s) diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 7af5237a503..a63da211a03 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2228,7 +2228,7 @@ describe Ci::Build do { key: 'CI_COMMIT_MESSAGE', value: pipeline.git_commit_message, public: true, masked: false }, { key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false }, { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false }, - { key: 'CI_COMMIT_REF_PROTECTED', value: pipeline.protected_ref?.to_s, public: true, masked: false } + { key: 'CI_COMMIT_REF_PROTECTED', value: (!!pipeline.protected_ref?).to_s, public: true, masked: false } ] end -- cgit v1.2.1