title: Jenkins Groovy - readyaml and writeyaml remove double quotes in yaml file
body: <p>I have a yaml file called <code>original.yml</code> with the following contents:</p>
  <pre><code>version: '2'
  services:
    vendor-app:
      image: vendor/vendor-app@sha256:f9db328fe5eed87f89cc0390a91c65eb92351fedda8a0c833b30c9147bd7ba07
      logging:
        driver: json-file
        options:
          max-size: &quot;50m&quot;
          max-file: &quot;2&quot;
      volumes:
      - /my_vol
      labels:
        io.rancher.container.pull_image: always
        com.vendor-app.builder.version: &quot;3bc55d00c&quot;
        com.vendor-app.built: &quot;Mon, 01 Jan 2021 19:32:24 -0000&quot;
  
    myservice:
      image: myregistry/myservice
      logging:
        driver: json-file
        options:
          max-size: &quot;50m&quot;
          max-file: &quot;2&quot;
      volumes:
      - /my_vol2
      labels:
        io.rancher.container.pull_image: always
  </code></pre>
  <p>I have another yaml file, I will call it <code>vendor.yml</code> that I get from vendor periodically, with the following content:</p>
  <pre><code>version: '2'
  services:
    vendor-app:
      image: vendor/vendor-app@sha256:ba065e9a04478fc17fd5b61b8c558616b7e9acba105668ef786f084545c32778
      logging:
        driver: json-file
        options:
          max-size: &quot;50m&quot;
          max-file: &quot;20&quot;
      volumes:
      - /my_vol
      labels:
        com.vendor-app.builder.version: &quot;7766jjc&quot;
        com.vendor-app.built: &quot;Fri, 14 Dec 2018 20:50:35 -0000&quot;
  </code></pre>
  <p>I would like to replace <code>image</code> in <code>original.yml</code> from <code>image</code> in <code>vendor.yml</code>, and merge <code>labels</code> from <code>vendor.yml</code> with the existing <code>labels</code> in <code>original.yml</code>. Basically the end result should be the following :</p>
  <pre><code>services:
    vendor-app:
      image: vendor/vendor-app@sha256:ba065e9a04478fc17fd5b61b8c558616b7e9acba105668ef786f084545c32778
      logging:
        driver: json-file
        options:
          max-size: &quot;50m&quot;
          max-file: &quot;2&quot;
      volumes:
      - /my_vol
      labels:
        io.rancher.container.pull_image: always
        com.vendor-app.builder.version: &quot;7766jjc&quot;
        com.vendor-app.built: &quot;Fri, 14 Dec 2018 20:50:35 -0000&quot;
  
    myservice:
      image: myregistry/myservice
      logging:
        driver: json-file
        options:
          max-size: &quot;50m&quot;
          max-file: &quot;2&quot;
      volumes:
      - /my_vol2
      labels:
        io.rancher.container.pull_image: always
  </code></pre>
  <p>I <em>almost</em> reached my goal by doing this :</p>
  <pre><code>Map merge(Map... maps) {
    Map result = [:]
    maps.each { map -&gt;
      map.each { k, v -&gt;
        result[k] = result[k] instanceof Map ? merge(result[k], v) : v
        }
      }
     result
    }
  
  
  def latest_yml = readYaml file:&quot;vendor.yml&quot;
  def current_yml = readYaml file:&quot;original.yml&quot;
  def new_yml = readYaml file:&quot;original.yml&quot;
  
  current_yml.services['vendor-app'].image = latest_yml.services['vendor'].image
  current_yml.services['vendor-app'].labels =  latest_yml.services['vendor-app'].labels
  writeYaml file:&quot;beforemerge.yml&quot;, data: current_yml
  
  println &quot;merge(new_yml, current_yml): &quot; + merge(new_yml, current_yml)
  writeYaml file:&quot;aftermerge.yml&quot;, data: merge(new_yml, current_yml)
  </code></pre>
  <p><em>Almost</em>, because this is what I get in <code>aftermerge.yml</code>:</p>
  <pre><code>services:
    vendor-app:
      image: vendor/vendor-app@sha256:ba065e9a04478fc17fd5b61b8c558616b7e9acba105668ef786f084545c32778
      logging:
        driver: json-file
        options:
          max-size: 50m
          max-file: '2'
      volumes:
      - /my_vol
      labels:
        io.rancher.container.pull_image: always
        com.vendor-app.builder.version: 7766jjc
        com.vendor-app.built: Fri, 14 Dec 2018 20:50:35 -0000
    myservice:
      image: myregistry/myservice
      logging:
        driver: json-file
        options:
          max-size: 50m
          max-file: '2'
      volumes:
      - /my_vol2
      labels:
        io.rancher.container.pull_image: always
  </code></pre>
  <p>As you can see, it has messed up the formatting somewhat...the double quotes from <code>com.vendor-app.built</code> and <code>com.vendor-app.builder.version</code> have disappeared and this obviously will cause havoc when I use the updated yaml file (the examples here are redacted versions of docker-compose.yml). The quoting around <code>max-size</code> and <code>max-file</code> are also changed to singles quotes only for <code>max-file</code> ?? Weird...</p>
  <p>Why is it doing this and how can I make the logic preserve the quoting?
  Is there a better way of doing this? Really all I want to do is get the values from <code>image</code> and <code>labels</code> from <code>vendor.yml</code> and use them to update the same values in <code>original.yml</code> (in the case of <code>labels</code>, appending onto the current value in <code>original.yml</code> as well as updating).</p>
  <p>Any help would be appreciated, thanks.</p>