Commit 344d6e6f authored by Pascal Bach's avatar Pascal Bach

Support YAML alias/anchor usage in .gitlab-ci.yml

This allows to reuse one job as a template for another one:

```
job1: &JOBTMPL
  script: execute-script-for-job

job2: *JOBTMPL

```

This also helps to solve some of the issues in #342
Signed-off-by: default avatarPascal Bach <pascal.bach@siemens.com>
Signed-off-by: default avatarFabio Huser <fabio.huser@siemens.com>
parent 75a67ac0
......@@ -10,7 +10,7 @@ module Ci
attr_reader :before_script, :image, :services, :variables, :path, :cache
def initialize(config, path = nil)
@config = YAML.safe_load(config, [Symbol])
@config = YAML.safe_load(config, [Symbol], [], true)
@path = path
unless @config.is_a? Hash
......
......@@ -427,6 +427,45 @@ module Ci
end
end
describe "YAML Alias/Anchor" do
it "is correctly supported for jobs" do
config = <<EOT
job1: &JOBTMPL
script: execute-script-for-job
job2: *JOBTMPL
EOT
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(2)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
except: nil,
stage: "test",
stage_idx: 1,
name: :job1,
only: nil,
commands: "\nexecute-script-for-job",
tag_list: [],
options: {},
when: "on_success",
allow_failure: false
})
expect(config_processor.builds_for_stage_and_ref("test", "master").second).to eq({
except: nil,
stage: "test",
stage_idx: 1,
name: :job2,
only: nil,
commands: "\nexecute-script-for-job",
tag_list: [],
options: {},
when: "on_success",
allow_failure: false
})
end
end
describe "Error handling" do
it "fails to parse YAML" do
expect{GitlabCiYamlProcessor.new("invalid: yaml: test")}.to raise_error(Psych::SyntaxError)
......
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