0

I have below conditional logic in the Drone YAML, but I saw that the control is not going inside that, even though drone branch is "develop". How to fix this, did I do anything wrong?

commands:
      - "./gradlew clean build"
      - echo "${DRONE_BRANCH}"
      - echo "${DRONE_BRANCH}" = "develop"
      - >
        if [ "${DRONE_BRANCH}" = "develop" ]; then
            export CLOUD_USER_KEY=$STAGE_CLOUD_USER_KEY
            export HOST_NAME="11.22.111.111"
        fi
      - >
        if [ "${DRONE_BRANCH}" = "master" ]; then
            export CLOUD_USER_KEY=$PROD_CLOUD_USER_KEY
            export HOST_NAME="11.22.111.112"
        fi

      - echo "CLOUD_USER_KEY "${CLOUD_USER_KEY}
      - echo "HOST NAME "${HOST_NAME}
halfer
  • 19,824
  • 17
  • 99
  • 186
Bravo
  • 8,589
  • 14
  • 48
  • 85

1 Answers1

0

> is the YAML indicator for a folded block scalar. Line folding in YAML means that a line break between two non-empty consecutive lines is changed into a space. This is not what you want when writing bash commands into YAML!

For example, this simple folded block scalar (using only parts of your original YAML file):

- >
  export CLOUD_USER_KEY=$STAGE_CLOUD_USER_KEY
  export HOST_NAME="11.22.111.111"

will be parsed as:

- "export CLOUD_USER_KEY=$STAGE_CLOUD_USER_KEY export HOST_NAME=\"11.22.111.111\"\n"

Which won't work. Use a literal block scalar instead which preserves line endings:

- |
  export CLOUD_USER_KEY=$STAGE_CLOUD_USER_KEY
  export HOST_NAME="11.22.111.111"
flyx
  • 35,506
  • 7
  • 89
  • 126
  • *still not working* is never a valid description of a problem. Since you have debug output in your YAML, show the actual output. – flyx Aug 07 '17 at 20:17