Can “if” statements be used in bitbucket pipelines?

前端 未结 1 1828
旧时难觅i
旧时难觅i 2021-02-19 20:54

Im trying to run the following step, but it does not execute the \"if\" steps (lines 5 and 6) (I\'m pretty sure they should as the directory tested for does not exist, i tried i

1条回答
  •  青春惊慌失措
    2021-02-19 21:14

    Basically, Bb Pipelines support conditions, be it file checks using -e or comparisons. For instance, these lines all do work:

    script:
      - '[ ! -e "$BITBUCKET_CLONE_DIR/missing.txt" ] && echo "File does not exist"'
      - 'if [ ! -e "$BITBUCKET_CLONE_DIR/missing.txt" ]; then echo "File does not exist"; fi'
      - if [ ! -e "$BITBUCKET_CLONE_DIR/missing.txt" ]; then echo "File does not exist"; fi
    

    As shown in the example, for some commands it can be needed to wrap the line in single quotes (here, only for demonstration purposes), so if Bb reports a syntax error, you should experiment with that.

    But: are you sure you really want $HOME? By default, you are in $BITBUCKET_CLONE_DIR – not in $HOME –, and therefore the curl call downloads the SDK to $BITBUCKET_CLONE_DIR.

    0 讨论(0)
提交回复
热议问题