【问题标题】:Could not parse .travis.yml无法解析 .travis.yml
【发布时间】:2018-05-27 10:36:03
【问题描述】:

我正在尝试使用 GitHub、Travis CI 和 AWS ECS 创建 CI 管道。当我将提交推送到 master 分支时,我在 travis CI 中遇到错误:'Could not parse .travis.yml'。我想不通,问题出在哪里。 Travis 没有提供有关错误的更多信息。

有一个代码,我正在使用:

.travis.yml

language: csharp
dist: trusty
sudo: required
mono: none
dotnet: 2.0.0
branches:
    only:
        - master
before_script:
    - chmod -R a+x scripts
script:
    - ./scripts/dotnet-build.sh
    - ./scripts/dotnet-publish.sh
    - ./scripts/docker-publish-travis.sh

dotnet-build.sh

 dotnet restore 
 dotnet build

dotnet-publish.sh

dotnet publish ./BookMeMobi2 -c Release -o ./bin/Docker

dotnet-publish-travis.sh

pip install --user awscli
eval $(aws ecr get-login --no-include-email --region eu-central-1)
docker build -t bookmemobi2 .
docker ps
docker tag bookmemobi2:latest 601510060817.dkr.ecr.eu-central-1.amazonaws.com/bookmemobi2:latest
docker push 601510060817.dkr.ecr.eu-central-1.amazonaws.com/bookmemobi2:latest

我不知道问题出在哪里。你可以帮帮我吗?

【问题讨论】:

  • 我以前用4个空格制表。在 yaml 文件中,我们应该使用 2 个空格列表。此外,windows 行尾存在问题(使用 UNIX eof)。

标签: docker travis-ci aws-ecs


【解决方案1】:

使用yamllint,您可以安装它,或者只是复制并粘贴到web-based version

通过问题中的示例,我得到:

():在第 7 行第 1 列扫描下一个标记时发现无法启动任何标记的字符

第 7 行有一个选项卡。请参阅“A YAML file cannot contain tabs as indentation”。


.travis.yml 文件的另一个在线资源是http://lint.travis-ci.org/,但此工具不拾取制表符。它通常是一个很好的资源。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。就我而言,我使用 python 来启动几个脚本。我把它们一个接一个地放在开头,并在开头加上一个连字符,就像你一样。所以我搜索发现我可以将它们全部放在一行中,每个脚本之间用“&”,我去掉了连字符。

    我有什么:

     script: 
     - python  test_Math_DC.py
     - python test_Math_Moy.py
     - python test_Math_Var.py
     - python test_Math_SQRT.py
    

    改为:

    script: python test_Math_DC.py & python test_Math_Moy.py & python test_Math_Var.py & python test_Math_SQRT.py
    

    你可以试试:

    script: ./scripts/dotnet-build.sh & ./scripts/dotnet-publish.sh & ./scripts/docker-publish-travis.sh
    

    或类似的东西:

    script: sh ./scripts/dotnet-build.sh & sh ./scripts/dotnet-publish.sh & sh ./scripts/docker-publish-travis.sh
    

    看看效果如何。

    【讨论】:

    • 就我而言,这是制表的问题。我有 4 个空格列表的设置 vs 代码。 .Yaml 文件需要 2 个空格列表。
    【解决方案3】:

    travis cli 工具有一个 linter

    gem install travis
    

    但是,它仅针对示例给出警告。此外,它目前不适用于所有功能,例如阶段。

    $ travis lint
    Warnings for .travis.yml:
    [x] unexpected key mono, dropping
    [x] unexpected key dotnet, dropping
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      相关资源
      最近更新 更多