【问题标题】:How can I write a multi-line if block on Bitbucket Pipeline?如何在 Bitbucket Pipeline 上编写多行 if 块?
【发布时间】:2019-01-21 07:42:58
【问题描述】:

From here我了解到 Bitbucket Pipeline 支持 ifs 语句。

如何在 if 语句中做多行块?

这不计算:

    script:
      - if [ $BITBUCKET_BRANCH == "master" ];
        then;
          echo Line1
          echo line2
        fi;

【问题讨论】:

    标签: bitbucket-pipelines


    【解决方案1】:

    我发现这行得通:

    - if [ $BITBUCKET_BRANCH == 'master' ]; then
    - echo "We are on master"
    - fi
    

    【讨论】:

      【解决方案2】:

      Bitbucket 管道是用 YAML 编写的,因此您可以充分利用 YAML 语言。

      对于多行,您还可以使用|> 运算符。

      - >
        if [ $BITBUCKET_BRANCH == 'master' ]; then
          echo "We are on master :)"
        else
          echo "We are not on master :("
        fi
      

      更多信息: https://yaml-multiline.info/

      注意:我猜这个用例只是一个示例,但您也可以直接按分支过滤管道步骤: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html#Configurebitbucket-pipelines.yml-SectionDescription

      【讨论】:

      • 这应该是公认的答案,比在管道中作为单个语句运行要好得多
      猜你喜欢
      • 2022-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      相关资源
      最近更新 更多