microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.43k stars 2.59k forks source link

[BUG]: dotnet publish arguments removes and changes quotes, makes it impossible to set ContainerTags #20116

Open jatocode opened 4 days ago

jatocode commented 4 days ago

New issue checklist

Task name

DotNetCoreCLI@2

Task version

2.*

Issue Description

The dotnet publish task removes or changes quotes in the arguments list. I found a workaround that preserves the quotes as containertags prefers with single+double '". But then some other transformations seems to be happening

Command

- task: DotNetCoreCLI@2
      inputs:
        command: 'publish'
        publishWebProjects: false    
        projects: |
           .... my projects ...
        arguments: -p ContainerImageTags="'\"latest;dev;$(tag);$(buildnum)\"'" -p:PublishProfile="mespressen"

The same dotnet publish command works in local commandline.

Error

My containerimagetags get set to what seems to be correct, but then some tags gets removed and the semicolon is replaced by a comma.

Logs

/usr/bin/dotnet publish /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj -p ContainerImageTags='"latest;dev;publish-images;20240704.26"' -p:PublishProfile=mespressen
  Determining projects to restore...
  Restored /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj (in 4.8 sec).
  APIGW -> /home/vsts/work/1/s/Infrastructure/APIGW/bin/Release/net8.0/linux-x64/APIGW.dll
  APIGW -> /home/vsts/work/1/s/Infrastructure/APIGW/bin/Release/net8.0/linux-x64/publish/
/usr/share/dotnet/sdk/8.0.302/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010: Invalid ContainerImageTags provided: 'latest,20240704.26'. ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period. [/home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj]

Easy to spot in an image, compare the blue line with the error last in the image image

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

ubuntu-latest

Relevant log output

Starting: DotNetCoreCLI
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.242.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
/usr/bin/dotnet publish /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj -p ContainerImageTags='"latest;dev;publish-images;20240704.26"' -p:PublishProfile=mespressen
  Determining projects to restore...
  Restored /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj (in 4.8 sec).
  APIGW -> /home/vsts/work/1/s/Infrastructure/APIGW/bin/Release/net8.0/linux-x64/APIGW.dll
  APIGW -> /home/vsts/work/1/s/Infrastructure/APIGW/bin/Release/net8.0/linux-x64/publish/
/usr/share/dotnet/sdk/8.0.302/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010: Invalid ContainerImageTags provided: 'latest,20240704.26'. ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period. [/home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj]
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
/usr/bin/dotnet publish /home/vsts/work/1/s/Services/Alarm/Service/MPR.Alarm.Service.csproj -p ContainerImageTags='"latest;dev;publish-images;20240704.26"' -p:PublishProfile=mespressen

Full task logs with system.debug enabled

 
2024-07-05T06:32:58.3630141Z ##[debug]which '/usr/bin/dotnet'
2024-07-05T06:32:58.3630465Z ##[debug]found: '/usr/bin/dotnet'
2024-07-05T06:32:58.3630789Z ##[debug]/usr/bin/dotnet arg: publish
2024-07-05T06:32:58.3631176Z ##[debug]/usr/bin/dotnet arg: /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj
2024-07-05T06:32:58.3631676Z ##[debug]/usr/bin/dotnet arg: -p ContainerImageTags="'\"latest;dev;publish-images;20240705.1\"'" -p:PublishProfile="mespressen"
2024-07-05T06:32:58.3632118Z ##[debug]exec tool: /usr/bin/dotnet
2024-07-05T06:32:58.3632432Z ##[debug]arguments:
2024-07-05T06:32:58.3632752Z ##[debug]   publish
2024-07-05T06:32:58.3633091Z ##[debug]   /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj
2024-07-05T06:32:58.3633447Z ##[debug]   -p
2024-07-05T06:32:58.3633791Z ##[debug]   ContainerImageTags='"latest;dev;publish-images;20240705.1"'
2024-07-05T06:32:58.3634179Z ##[debug]   -p:PublishProfile=mespressen
2024-07-05T06:32:58.3634943Z [command]/usr/bin/dotnet publish /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj -p ContainerImageTags='"latest;dev;publish-images;20240705.1"' -p:PublishProfile=mespressen
2024-07-05T06:32:59.7844842Z ##[debug]Agent environment resources - Disk: / Available 21150.00 MB out of 74244.00 MB, Memory: Used 650.00 MB out of 6921.00 MB, CPU: Usage 65.61%
2024-07-05T06:33:04.1962001Z   Determining projects to restore...
2024-07-05T06:33:04.7871940Z ##[debug]Agent environment resources - Disk: / Available 21150.00 MB out of 74244.00 MB, Memory: Used 707.00 MB out of 6921.00 MB, CPU: Usage 45.72%
2024-07-05T06:33:09.1453940Z   Restored /home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj (in 3.95 sec).
2024-07-05T06:33:09.7881420Z ##[debug]Agent environment resources - Disk: / Available 21082.00 MB out of 74244.00 MB, Memory: Used 765.00 MB out of 6921.00 MB, CPU: Usage 35.15%
2024-07-05T06:33:14.7892313Z ##[debug]Agent environment resources - Disk: / Available 21082.00 MB out of 74244.00 MB, Memory: Used 809.00 MB out of 6921.00 MB, CPU: Usage 28.61%
2024-07-05T06:33:18.2491936Z   APIGW -> /home/vsts/work/1/s/Infrastructure/APIGW/bin/Release/net8.0/linux-x64/APIGW.dll
2024-07-05T06:33:18.3085973Z   APIGW -> /home/vsts/work/1/s/Infrastructure/APIGW/bin/Release/net8.0/linux-x64/publish/
2024-07-05T06:33:18.4928785Z /usr/share/dotnet/sdk/8.0.302/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010: Invalid ContainerImageTags provided: 'latest,20240705.1'. ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period. [/home/vsts/work/1/s/Infrastructure/APIGW/APIGW.csproj]
2024-07-05T06:33:18.5889939Z ##[debug]Exit code 1 received from tool '/usr/bin/dotnet'
  

Repro steps

No response

ivanduplenskikh commented 4 days ago

@jatocode, could you try enclosing ContainerImageTags with escaped double quotes?

- task: DotNetCoreCLI@2
      inputs:
        command: 'publish'
        publishWebProjects: false    
        projects: |
           .... my projects ...
        arguments: -p ContainerImageTags="\"latest;dev;$(tag);$(buildnum)\"" -p:PublishProfile="mespressen"
jatocode commented 3 days ago

That actually seemed to work!! Thank you. I though I had tried all possible versions of escaped quotes...

I was under the impression that single quoutes where needed. based on this: Microsoft containerize app