可以“如果"语句可用于bitbucket管道? [英] Can "if" statements be used in bitbucket pipelines?

查看:134
本文介绍了可以“如果"语句可用于bitbucket管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下步骤,但是它不执行如果"步骤(第5行和第6行)(我很确定它们应该为被测试的目录不存在,所以我尝试了多种格式bash如果失败,但所有失败. 有没有一种方法可以比我正在使用的条件进行测试?

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 in multiple formats of bash if, but all of them fails. Is there a way to test for a condition than the one I'm using?

   - step:
      name: Google Cloud SDK Installation
      caches:
        - pip
        - cloudsdk
      script:
        - export ENV=dev
        - source scripts/setenv.sh
        - export CLOUDSDK_CORE_DISABLE_PROMPTS=1
        - SDK_FILENAME=google-cloud-sdk-$SDK_VERSION-linux-x86_64.tar.gz
        - if [ ! -e ${HOME}/google-cloud-sdk ] ; then `curl -O -J https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${SDK_FILENAME}`; fi
        - if [ ! -e ${HOME}/google-cloud-sdk ] ; then `tar -zxvf ${SDK_FILENAME} --directory ${HOME}`; fi
        - export PATH=${PATH}:${HOME}/google-cloud-sdk/bin
        - GAE_PYTHONPATH=${HOME}/google_appengine
        - export PYTHONPATH=${PYTHONPATH}:${GAE_PYTHONPATH}
        - python scripts/fetch_gae_sdk.py $(dirname "${GAE_PYTHONPATH}")

推荐答案

基本上,BB管道支持条件,可以使用-e进行文件检查或进行比较.例如,这些行都起作用:

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

如示例中所示,对于某些命令,可能需要将行用单引号引起来(此处,仅用于演示目的),因此,如果Bb报告语法错误,则应对此进行试验.

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.

但是:您确定您确实要$HOME吗?默认情况下,您位于$BITBUCKET_CLONE_DIR中-不在$HOME中,因此curl调用会将SDK下载到$BITBUCKET_CLONE_DIR.

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.

这篇关于可以“如果"语句可用于bitbucket管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆