Search code examples
gitlabyamlcicd

YAML need to use # inside but not comment it


I need to use this code inside a YAML file to remove chars from a file, but on YAML # is comment and cannot execute all after the #

Example of what I want to execute: echo $(tr -d '[\[\]#,"]')

Is there any workaround to achieve want I need?


Solution

  • The easiest, probably, in you case, would be to use a folded block style, because your tr does have simple and double quotes in it, and going with a quoted string would need you to go in escaping characters, which could be a pain.

    But for the sake of completeness, here are the possible ways:

    foo: "# I am not a comment, as I am enclosed in double quoted string"
    bar: '# me neither, as I am enclosed in a single quoted string'
    baz: |
      # so ain't I, in a literal style block
    qux: >
      # I don't differ from the three above, in a folded style block
    

    So, in your case, what you could do is:

    my_command: >-
      echo $(tr -d '[\[\]#,"]')