序列条目位桶管道的错误缩进

Bad indentation of a sequence entry bitbucket pipelines

我目前在 bitbucket 管道中有一个步骤可以做一些事情。最后一步是启动 aws ecs 任务,如下所示:

  - step:
      name: Migrate database
      script:
        - curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
        - apt-get update
        - apt-get install -y unzip python
        - unzip awscli-bundle.zip
        - ./awscli-bundle/install -b ~/bin/aws
        - export PATH=~/bin:$PATH
        - aws ecs run-task --cluster test-cluster --task-definition test-task --overrides '{ "containerOverrides": [ { "name": "test-container", "command": [ "echo", "hello world" ], "environment": [ { "name": "APP_ENV", "value": "local" } ] } ] }' --network-configuration '{ "awsvpcConfiguration": { "subnets": ["subnet-xxxxxxx"], "securityGroups": ["sg-xxxxxxx"], "assignPublicIp": "ENABLED" }}' --launch-type FARGATE

验证失败并出现错误:

Bad indentation of a sequence entry bitbucket pipelines

将语句拆分成多行也不起作用。这里正确的方法是什么?

问题是冒号后跟 space,这会导致 YAML 解析器将其解释为映射而不是字符串。

最简单的解决方案是移动

aws ecs run-task --cluster test-cluster --task-definition test-task --overrides '{ "containerOverrides": [ { "name": "test-container", "command": [ "echo", "hello world" ], "environment": [ { "name": "APP_ENV", "value": "local" } ] } ] }' --network-configuration '{ "awsvpcConfiguration": { "subnets": ["subnet-xxxxxxx"], "securityGroups": ["sg-xxxxxxx"], "assignPublicIp": "ENABLED" }}' --launch-type FARGATE

进入脚本文件,并从 Pipelines 中调用它。

您还可以删除任何“:”字符后的所有 space。但是考虑到那里 JSON 的数量,您在修改它时可能会再次遇到同样的问题。所以脚本文件可能是这里更简单的选择。