VSTS docker任务在“&&"上失败docker RUN命令中的令牌 [英] VSTS docker task failed on '&&' token in docker RUN command
问题描述
我为VSTS(在线Visual Studio)中的ASP.NET Core应用程序配置CI. 我添加了"docker-compose build"任务来构建定义,但是它失败并出现错误:
I configuring CI for my ASP.NET Core application in VSTS (visual studio online). I've added "docker-compose build" task to build definition but it fails with errors:
Step 4/9 : RUN dotnet restore QuizService.sln && dotnet publish QuizService.sln -c Release -o obj/Docker/publish
---> Running in 7ea0cf1881d1
... rence = 'SilentlyContinue'; dotnet restore QuizService.sln && dotnet ...
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
Service 'quizservice' failed to build: The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore QuizService.sln && dotnet publish QuizService.sln -c Release -o obj/Docker/publish' returned a non-zero code: 1
##[error]Building quizservice
##[error]Service 'quizservice' failed to build: The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore QuizService.sln && dotnet publish QuizService.sln -c Release -o obj/Docker/publish' returned a non-zero code: 1
##[error]C:\ProgramData\Chocolatey\bin\docker-compose.exe failed with return code: 1
问题出在我的dockerfile上:
The problem is with my dockerfile on line:
RUN dotnet restore QuizService.sln && dotnet publish QuizService.sln -c Release -o obj/Docker/publish
码头工人以某种方式不理解'&&'操作员: 令牌'&&'不是有效的语句分隔符.异常本身似乎与powershell有关,而不与docker有关. Poweshell没有&&"语法,但是为什么它在这里开始使用Powershell而不是cmd.exe来运行命令?
Somehow docker does not understand '&&' operator: The token '&&' is not a valid statement separator. The exception itself seems to be related to powershell rather than to docker. Poweshell has no '&&' syntax but why it starts using powershell for RUN command here instead of cmd.exe?
当我在开发机器上本地构建时,它就像一种魅力.
It works like a charm when I build locally on my dev machine.
有人遇到同样的问题吗?
Do somebody faced the same problem?
推荐答案
问题出在错误的构建代理类型中. 托管的VS2017"构建代理无法构建项目,因为它使用带有Windows容器的docker(并且将powershell作为默认外壳).但是在我的开发机上,我将docker与linux容器一起使用(/bin/sh为默认外壳).选择正确的构建代理类型可以解决此问题(因为/bin/sh理解'&&').
The problem was in incorrect build agent type. "Hosted VS2017" build agent failed to build project because it uses docker with windows containers (and powershell as a default shell). But on my dev machine I use docker with linux containers (with /bin/sh as a default shell). Choosing the correct build agent type fixed the problem (because /bin/sh understands '&&').
这篇关于VSTS docker任务在“&&"上失败docker RUN命令中的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!