简体   繁体   English

Gitlab azure cli多行参数

[英]Gitlab azure cli multiple lines parameters

I'm trying to create a ci pipeline in Gitlab to create a new storage account.我正在尝试在 Gitlab 中创建一个 ci 管道以创建一个新的存储帐户。 As this resources has lots of optional parameters, putting it all on one line makes it quite long so I wanted to break it up.由于此资源有很多可选参数,因此将它们全部放在一行中会使它变得很长,所以我想将其分解。 Running it in my local bash instance works fine but not on gitlab. How can I split commands into several rows in gitlab?在我的本地 bash 实例中运行它可以正常工作,但在 gitlab 上却不行。如何在 gitlab 中将命令拆分为多行? This is how my CI looks like:这是我的 CI 的样子:

    image: mcr.microsoft.com/azure-cli:2.9.1

stages:
  - preparation

create_storage:
  stage: preparation
  script:
    # Create storage account if not exists:
    - storageAccountAvailable=$(az storage account check-name --name myStorage --query "nameAvailable")
    - >
      if [[ $storageAccountAvailable = "true" ]]; then
        az group create --location westeurope --name myStorageRG
        az storage account create \
          --name myStorage \
          --resource-group myStorageRG \
          --sku Standard_LRS \
          --min-tls-version TLS1_2 \
          --https-only true \
          --access-tier Hot \
          --default-action Deny \
          --public-network-access Disabled

        az storage account network-rule add --account-name myStorage --ip-address 1.1.1.1
      fi
  allow_failure: false

If I use backslashes like above, it fails on the last row, --public.network-access Disabled , saying its not recognizing the argument.如果我像上面那样使用反斜杠,它会在最后一行--public.network-access Disabled上失败,表示它无法识别该参数。 If I remove the backslashes entirely it fails at the beggining and complaings that I am missing the resourcesgroup.如果我完全删除反斜杠,它会在开始时失败并抱怨我缺少资源组。

Split Long commands into multiple lines to view a better readability.将长命令拆分为多行以查看更好的可读性。 So you can use the literal |所以你可以使用文字| and folded > ().折叠> ()。 Refer YAML multiline block scalar indicators .参考YAML multiline block scalar indicators

According to the Gitlab Doc we came to know,根据我们了解到的Gitlab Doc

If multiple commands are combined into one command string, only the last command's failure or success is reported.如果多个命令组合成一个命令字符串,则仅报告最后一个命令的失败或成功。 Failures from earlier commands are ignored due to a bug . 由于错误,忽略早期命令的失败 To work around this, run each command as a separate script item, or add an exit 1 command to each command string.要解决此问题,请将每个命令作为单独的script项运行,或将exit 1命令添加到每个命令字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM