GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.59k stars 1.42k forks source link

Error build .NET applications in pipeline gitlab. Flag -o break #3260

Open Andymnm opened 1 month ago

Andymnm commented 1 month ago

Снимок экрана 2024-07-24 115913

flag break -o in command dotnet publish -c $CONF -a $TARGETARCH --output /app

INFO[0793] Running: [/bin/sh -c dotnet publish -c $CONF -a $TARGETARCH --output /app] 
MSBUILD : error MSB1001: Unknown switch.
    Full command line: '/usr/share/dotnet/sdk/8.0.303/MSBuild.dll -maxcpucount -verbosity:m -nologo -restore -target:Publish --property:_IsPublishing=true -property:Configuration=Release -property:RuntimeIdentifier=linux-musl---output -property:DOTNET_CLI_DISABLE_PUBLISH_AND_PACK_RELEASE=true /app -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/share/dotnet/sdk/8.0.303/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/share/dotnet/sdk/8.0.303/dotnet.dll'
  Switches appended by response files:
Switch: /app
For switch syntax, type "MSBuild -help"

Dockerfile

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG TARGETARCH
ARG CONF=Release
WORKDIR /source

COPY *.csproj .

RUN dotnet restore --no-cache

COPY . .
RUN dotnet publish -c $CONF -o /app -a $TARGETARCH --no-restore

FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine

WORKDIR /app
COPY --from=build /app .
USER $APP_UID
ENTRYPOINT ["./WebAPI"]

Pipeline

publish-job:
    stage: publish
    when: manual
    image:
        name: gcr.io/kaniko-project/executor:debug
        entrypoint: [""]
    script:
        - cp $APPSETTINGS_PRODUCTION appsettings.Production.json
        - /kaniko/executor
          --context ${CI_PROJECT_DIR}/WebAPI
          --dockerfile ${CI_PROJECT_DIR}/WebAPI/Dockerfile
          --destination ${CI_REGISTRY_IMAGE}:latest
          --cache=true
Andymnm commented 1 month ago

Attempt to change the command:

Снимок экрана 2024-07-24 115913

The last flag is read without a space

Andymnm commented 1 month ago

Solution

Wrap CICD variables in quotation marks.

RUN dotnet publish -c "$CONF" -o /app -a "$TARGETARCH" --no-restore