为什么我会收到错误:"Error while executing command: dotnet publish"?



我创建了buildspec.ymlAWS CodeBuild中使用的文件当我运行它时,我得到下面的错误:

COMMAND_EXECUTION_ERROR消息:执行命令时出错:dotnetpublish -c release -o build/outputs/Host。原因:退出状态1

我已经检查了我在'-o'参数中传递的路径,我甚至已经删除了它,但我仍然得到错误。

我正在使用dotnet 5.0。我需要在构建它之前安装它吗?如果是,我该怎么做?

下面我把buildspec.yml中重要的代码片段:

version: 0.2
phases:
install:
runtime-versions:
docker: 18

pre_build:
commands:
- echo pre-build started on `date`
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

build:
commands:
- echo Building dotnet API...
- cd aspnet-core/src/SITR.Web.Host
- echo Executing dotnet restore...
- dotnet restore
- echo Executing dotnet publish...
- dotnet publish -c release -o ../../../docker/build/outputs/Host

post_build:
commands:
- echo Pushing the Docker image...
- docker-compose --file=docker-compose-qa.yml push
- echo Build completed on `date`

dotnet: 5.0仅在dotnet运行时支持。但是你正在使用docker运行时。所以你要么改变你的运行时,要么在运行时手动设置/安装dotnet。

Marcin的回复帮助我想出了解决方案。我在另一个答案中记录了我需要做的事情,也许它会帮助别人。

对于我的构建我需要使用dotnet 5nodejs (npm)码头工人.

问题是我正在使用Amazon Linux 2根据该文档dotnet 5目前仅在Ubuntu 5.0中可用.

最初我还是有点困惑,因为我认为我需要安装docker,但实际上它已经安装在ubuntu 5.0镜像中。为了测试这一点,我编辑了我的CodeBuild并将版本更改为Ubuntu 5.0使用docker --version命令运行buildspec,检查日志。

version: 0.2
phases:
install:
runtime-versions:
dotnet: 5.0
nodejs: 14
commands:
- docker --version

基本上我需要切换到Ubuntu 5.0版本和我的构建规范。Yml是这样的:

version: 0.2
phases:
install:
runtime-versions:
dotnet: 5.0
nodejs: 14
pre_build:
commands:
- echo pre-build started on `date`
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

build:
commands:
- echo Building dotnet API...
- cd aspnet-core/src/SITR.Web.Host
- echo Executing dotnet restore...
- dotnet restore
- echo Executing dotnet publish...
- dotnet publish -c release -o ../../../docker/build/outputs/Host

post_build:
commands:
- echo Pushing the Docker image...
- docker-compose --file=docker-compose-qa.yml push
- echo Build completed on `date`

相关内容