4
votes

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?

3
You can share the detail log on the OneDrive.starian chen-MSFT
Do you solve this issue?starian chen-MSFT
It was a stupid mistake: there are several types of build agents in VSTS. I incorrectly chose "Hosted VS2017" which 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) to build and test my project. So choosing the correct build agent type fixed the problem (because /bin/sh understands '&&'). Your answer about changing shell is also correct but in my case I should not change the shell I just need to choose correct build agent,Philipp Bocharov

3 Answers

5
votes

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 '&&').

2
votes

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'
1
votes

If you have docker desktop installed, by default it starts with Windows Container.

From the Docker Desktop menu, select Switch to Linux containers, in order for && symbol to work.