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
The problem is with my dockerfile on line:
RUN dotnet restore QuizService.sln && dotnet publish QuizService.sln -c Release -o obj/Docker/publish
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?
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 '&&').
You can change the shell by using Shell command:
SHELL ["cmd", "/S"", "/C"]
Or changing it by specifying in Run command directly:
RUN /bin/bash -c 'source $HOME/.bashrc; echo $HOME'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With