Skip to content
Snippets Groups Projects
Commit 1e506507 authored by Tim Sharpe's avatar Tim Sharpe
Browse files

(#290) Do not manually generate YAML in .gitlab-ci.yml

Use `YAML.dump` to generate the custom job YAML rather than trying to
manually walk the hash and render it.

Given the `.sync.yml` in #290:
```
---
.gitlab-ci.yml:
  override: true
  custom:
    custom_stages:
      - 'unit'
    custom_jobs:
      testjob:
        stage: unit
        image: ruby:2.5.3
        script:
          - 'echo 1'
        artifacts:
          reports:
            junit: 'tmp/*.xml'
```

The rendered `.gitlab-ci.yml` is now:
```
---
stages:
  - unit

before_script:
  - bundle -v
  - rm Gemfile.lock || true
  - gem update --system $RUBYGEMS_VERSION
  - gem --version
  - bundle -v
  - bundle install

testjob:
  stage: unit
  image: ruby:2.5.3
  script:
  - echo 1
  artifacts:
    reports:
      junit: tmp/*.xml
```
parent 643529aa
No related branches found
No related tags found
No related merge requests found
...@@ -116,35 +116,5 @@ beaker: ...@@ -116,35 +116,5 @@ beaker:
<% end -%> <% end -%>
<% end -%> <% end -%>
<% if configs['custom_jobs'] -%> <% if configs['custom_jobs'] -%>
<% configs['custom_jobs'].each do |job, params| -%> <%= YAML.dump(configs['custom_jobs']).sub(%r{\A---\r?\n}m, '') %>
<%= job %>:
<% params.each do |param, config| -%>
<% if (config.is_a?(Array) || config.is_a?(Hash)) && config.empty? -%>
<%= param %>: <%= config.inspect %>
<% elsif config.is_a?(Array) -%>
<%= param %>:
<% config.each do |element| -%>
- <%= element %>
<% end -%>
<% elsif config.is_a?(Hash) -%>
<%= param %>:
<% config.each do |element, value| -%>
<% if value.is_a?(Array) -%>
<% if value.empty? -%>
<%= element %>: <%= value.inspect %>
<% else -%>
<%= element %>:
<% value.each do |content| -%>
- <%= content %>
<% end -%>
<% end -%>
<% else -%>
<%= element %>: '<%= value %>'
<% end -%>
<% end -%>
<% else -%>
<%= param %>: '<%= config %>'
<% end -%>
<% end %>
<% end -%>
<% end -%> <% end -%>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment