Home > Software engineering >  How to you escape special character from bitbucket pipeline
How to you escape special character from bitbucket pipeline

Time:10-25

I have a yml bitbucket pipeline where I would like to auto commit a message containing # and :

I am doing :

- git commit -m "[skip ci] $ISSUE #comment Link : $LINK"

The issue is the pipeline don't run cause it consider # to be a comment.

I tried to escape it using

 - git commit -m |-
    "[skip ci] $ISSUE #comment Link : $LINK"

or

 - git commit -m |-
    "[skip ci] $ISSUE '#'comment Link ':' $LINK"

but they dont work as expected

I am expecting a commit message like "[skip ci] UI-12 #comment Link : www.test.com/123"

What I get is either

bash: opt/atlassian/pipelines/agent/tmp/bashScript17301903987873752811.sh: line 23: unexpected EOF while looking for matching

or the ' remaining

How can I achieve this ?

CodePudding user response:

Check first if, as described in Advanced techniques for writing pipes, strong quoting would be enough:

 - git commit -m |-
       '[skip ci] $ISSUE #comment Link :'" $LINK"
      ^^^                              ^^^

If not, as commented:

 - git commit -m |-
       "[skip ci] $ISSUE \#comment Link : $LINK"
                         ^^^

CodePudding user response:

There are (at least) two sets of quoting to deal with here:

  • YAML quoting, which you've sort-of addressed, and
  • shell quoting, which you've also sort-of addressed.

Without actually trying it (as I don't have any Bitbucket setup of my own), I believe that this suffices:

      - step:
        script:
          - |-
            git commit -m "[skip ci] $ISSUE #comment Link : $LINK"

Note that there are some issues with yaml 1.1 vs 1.2; see this comment on How to escape colons and other special characters in a YAML string?

  • Related