Commit 81910022 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/ci-config-hidden-key-validation' into 'master'

Do not enforce using a hash with hidden ci key

## What does this MR do?

This MR remove the validation rule that was to strict.

## Why was this MR needed?

Enforcing hidden CI job configuration to be a hash, narrows options of using YAML anchors, and was not backwards compatbile.

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- Tests
  - [x] Added for this feature/bug
  - [ ] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Closes #21512

See merge request !6079
parents 0357df0c f4f191c1
...@@ -47,6 +47,7 @@ v 8.11.4 (unreleased) ...@@ -47,6 +47,7 @@ v 8.11.4 (unreleased)
- Fix broken gitlab:backup:restore because of bad permissions on repo storage !6098 (Dirk Hörner) - Fix broken gitlab:backup:restore because of bad permissions on repo storage !6098 (Dirk Hörner)
v 8.11.3 (unreleased) v 8.11.3 (unreleased)
- Do not enforce using hash with hidden key in CI configuration. !6079
- Allow system info page to handle case where info is unavailable - Allow system info page to handle case where info is unavailable
- Label list shows all issues (opened or closed) with that label - Label list shows all issues (opened or closed) with that label
- Don't show resolve conflicts link before MR status is updated - Don't show resolve conflicts link before MR status is updated
......
...@@ -39,7 +39,7 @@ If you want a quick introduction to GitLab CI, follow our ...@@ -39,7 +39,7 @@ If you want a quick introduction to GitLab CI, follow our
- [before_script and after_script](#before_script-and-after_script) - [before_script and after_script](#before_script-and-after_script)
- [Git Strategy](#git-strategy) - [Git Strategy](#git-strategy)
- [Shallow cloning](#shallow-cloning) - [Shallow cloning](#shallow-cloning)
- [Hidden jobs](#hidden-jobs) - [Hidden keys](#hidden-keys)
- [Special YAML features](#special-yaml-features) - [Special YAML features](#special-yaml-features)
- [Anchors](#anchors) - [Anchors](#anchors)
- [Validate the .gitlab-ci.yml](#validate-the-gitlab-ci-yml) - [Validate the .gitlab-ci.yml](#validate-the-gitlab-ci-yml)
...@@ -934,24 +934,27 @@ variables: ...@@ -934,24 +934,27 @@ variables:
GIT_DEPTH: "3" GIT_DEPTH: "3"
``` ```
## Hidden jobs ## Hidden keys
>**Note:** >**Note:**
Introduced in GitLab 8.6 and GitLab Runner v1.1.1. Introduced in GitLab 8.6 and GitLab Runner v1.1.1.
Jobs that start with a dot (`.`) will be not processed by GitLab CI. You can Keys that start with a dot (`.`) will be not processed by GitLab CI. You can
use this feature to ignore jobs, or use the use this feature to ignore jobs, or use the
[special YAML features](#special-yaml-features) and transform the hidden jobs [special YAML features](#special-yaml-features) and transform the hidden keys
into templates. into templates.
In the following example, `.job_name` will be ignored: In the following example, `.key_name` will be ignored:
```yaml ```yaml
.job_name: .key_name:
script: script:
- rake spec - rake spec
``` ```
Hidden keys can be hashes like normal CI jobs, but you are also allowed to use
different types of structures to leverage special YAML features.
## Special YAML features ## Special YAML features
It's possible to use special YAML features like anchors (`&`), aliases (`*`) It's possible to use special YAML features like anchors (`&`), aliases (`*`)
...@@ -967,7 +970,7 @@ Introduced in GitLab 8.6 and GitLab Runner v1.1.1. ...@@ -967,7 +970,7 @@ Introduced in GitLab 8.6 and GitLab Runner v1.1.1.
YAML also has a handy feature called 'anchors', which let you easily duplicate YAML also has a handy feature called 'anchors', which let you easily duplicate
content across your document. Anchors can be used to duplicate/inherit content across your document. Anchors can be used to duplicate/inherit
properties, and is a perfect example to be used with [hidden jobs](#hidden-jobs) properties, and is a perfect example to be used with [hidden keys](#hidden-keys)
to provide templates for your jobs. to provide templates for your jobs.
The following example uses anchors and map merging. It will create two jobs, The following example uses anchors and map merging. It will create two jobs,
...@@ -975,7 +978,7 @@ The following example uses anchors and map merging. It will create two jobs, ...@@ -975,7 +978,7 @@ The following example uses anchors and map merging. It will create two jobs,
having their own custom `script` defined: having their own custom `script` defined:
```yaml ```yaml
.job_template: &job_definition # Hidden job that defines an anchor named 'job_definition' .job_template: &job_definition # Hidden key that defines an anchor named 'job_definition'
image: ruby:2.1 image: ruby:2.1
services: services:
- postgres - postgres
...@@ -1081,7 +1084,7 @@ test:mysql: ...@@ -1081,7 +1084,7 @@ test:mysql:
- ruby - ruby
``` ```
You can see that the hidden jobs are conveniently used as templates. You can see that the hidden keys are conveniently used as templates.
## Validate the .gitlab-ci.yml ## Validate the .gitlab-ci.yml
......
...@@ -5,11 +5,10 @@ module Gitlab ...@@ -5,11 +5,10 @@ module Gitlab
## ##
# Entry that represents a hidden CI/CD job. # Entry that represents a hidden CI/CD job.
# #
class HiddenJob < Entry class Hidden < Entry
include Validatable include Validatable
validations do validations do
validates :config, type: Hash
validates :config, presence: true validates :config, presence: true
end end
......
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
def compose! def compose!
@config.each do |name, config| @config.each do |name, config|
node = hidden?(name) ? Node::HiddenJob : Node::Job node = hidden?(name) ? Node::Hidden : Node::Job
factory = Node::Factory.new(node) factory = Node::Factory.new(node)
.value(config || {}) .value(config || {})
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::HiddenJob do describe Gitlab::Ci::Config::Node::Hidden do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) { { image: 'ruby:2.2' } } let(:config) { [:some, :array] }
describe '#value' do describe '#value' do
it 'returns key value' do it 'returns key value' do
expect(entry.value).to eq(image: 'ruby:2.2') expect(entry.value).to eq [:some, :array]
end end
end end
...@@ -21,17 +21,6 @@ describe Gitlab::Ci::Config::Node::HiddenJob do ...@@ -21,17 +21,6 @@ describe Gitlab::Ci::Config::Node::HiddenJob do
end end
context 'when entry value is not correct' do context 'when entry value is not correct' do
context 'incorrect config value type' do
let(:config) { ['incorrect'] }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'hidden job config should be a hash'
end
end
end
context 'when config is empty' do context 'when config is empty' do
let(:config) { {} } let(:config) { {} }
......
...@@ -74,7 +74,7 @@ describe Gitlab::Ci::Config::Node::Jobs do ...@@ -74,7 +74,7 @@ describe Gitlab::Ci::Config::Node::Jobs do
expect(entry.descendants.first(2)) expect(entry.descendants.first(2))
.to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job)) .to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job))
expect(entry.descendants.last) expect(entry.descendants.last)
.to be_an_instance_of(Gitlab::Ci::Config::Node::HiddenJob) .to be_an_instance_of(Gitlab::Ci::Config::Node::Hidden)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment