Variable substitution for # not working

I’m running drone v0.8 and I have an issue when DRONE_COMMIT_MESSAGE contains a “#”.

Let’s say the variable contains: Merged in release/1.0.8 (pull request #6).

I’m trying to run a command:

pipeline:   
  set-build-version:
    when:
      branch: master
    image: alpine
    commands:
      - echo "${DRONE_COMMIT_MESSAGE}" | grep -o -E 'release/.{0,5}|hotfix/.{0,5}'

Having the hashtag in message causes this output:
echo "Merged in release/1.0.8 (pull request

I tried to do a substitution to remove the “#” using:

  • ${DRONE_COMMIT_MESSAGE/#/}
  • ${DRONE_COMMIT_MESSAGE/\#/}
  • ${DRONE_COMMIT_MESSAGE/’#’/}

I still get the same output regardless.

I know that a # with a space in front in yaml will cause a line stop, but I assumed the variable substitution took place before the yaml parsing.

try

  • ${DRONE_COMMIT_MESSAGE/#/-}
  • ${DRONE_COMMIT_MESSAGE/\#/-}

in case it fails on replacing with empty string

I’ve tried both and same result as before.

I found the solution. If I put a leading space in front of the # it works in my case since the character is prefixed by a space in my case.

Looking through the substitution source code, looks like # is considered function character to determine what operation should happen, which would explain why I couldn’t use it without the leading space.