yaml

In YAML how can I comment a part of a line?


In YAML how can I comment a part of a line?

for example:

- name: "JAVA_OPTIONS"
  value: "-Dconfig.dir.path=$(CONF_PATH) -Dpoint.dir.path=$(POINT_PATH)-
Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) 
-DMY_POD_NAME=$(MY_POD_NAME)"

How can I comment a string inside the value line?

Like "-Dpoint.dir.path=$(POINT_PATH)" will be remarked but all the rest will take affect.


Solution

  • YAML only has comments that are in effect until the end of the line. So unless there is some other commenting mechanism implemented by the program that interprets the YAML data (unlikely), the best thing to do is copy the whole line, comment one version out, and adjust the other:

    - name: "JAVA_OPTIONS"
      # value: "-Dconfig.dir.path=$(CONF_PATH) -Dpoint.dir.path=$(POINT_PATH)-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) -DMY_POD_NAME=$(MY_POD_NAME)"
      value: "-Dpoint.dir.path=$(POINT_PATH)-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) -DMY_POD_NAME=$(MY_POD_NAME)"
    

    If you want to "roll-back" just move the comment token (#) from the one line to the other.

    In the above I adjusted your input to be valid YAML. Your example is not valid because you cannot have both a sequence element and a key-value pair on the same level with the same parent (in this case the YAML document root).