Trouble escaping double quotes in Azure pipelines DotNetCoreCLI task

189 views Asked by At

I'm trying to publish my .NET web app using the somewhat new built-in container support for the .NET SDK. In order to set the container image tags I need to pass a parameter in the arguments. This parameter needs to look like -p ContainerImageTags='"1.0.0;latest"', note the double quotes surrounded by the single quotes, it needs it that way for some reason.

So I would think the following would just work, but it doesn't. Now I'm using a block scalar for the arguments, which, if I'm not mistaken should leave my quotes alone, so no need to escape them.

  - task: DotNetCoreCLI@2
    displayName: 'Publish'
    inputs:
      command: 'publish'
      arguments: >-
        -p PublishProfile="DefaultContainer"
        -p ContainerRepository="my-repository"
        -p ContainerImageTags='"$(Build.BuildNumber);latest"'
        -p Version="$(Build.BuildNumber)"

But the output of this is:

/usr/bin/dotnet publish /home/vsts/work/1/s/src/the-web-project.csproj -p PublishProfile=DefaultContainer -p ContainerRepository=my-repository -p ContainerImageTags='2023.12.07.18;latest' -p Version=2023.12.07.18

so no double quotes. Thus, escaping the quotes like /" results in the following:

/usr/bin/dotnet publish /home/vsts/work/1/s/src/the-web-project.csproj -p PublishProfile=\DefaultContainer" -p ContainerRepository="my-repository" -p ContainerImageTags='"2023.12.07.19;latest"' -p Version="2023.12.07.19"

This is kinda better, except the first quote is just \ now, breaking the command. Only using escaped quotes on the ContainerImageTags just moves the problem creating -p ContainerImageTags='\2023.12.07.19;latest"'.

But then again, the YAML docs say escaping is unnecessary in block scalars. So, doing the same but with the Bash@3 task instead actually does what I want.

exec bash '/home/vsts/work/1/s/test' -p PublishProfile="DefaultContainer" -p ContainerRepository="my-repository" -p ContainerImageTags='"2023.12.07.18;latest"' -p Version="2023.12.07.18"

How do I get my quotes properly with the DotNetCoreCLI@2 task?

2

There are 2 answers

2
Bright Ran-MSFT On BEST ANSWER

You can set the arguments like as below on the DotNetCoreCLI@2 task.

  - task: DotNetCoreCLI@2
    displayName: 'Publish'
    inputs:
      command: 'publish'
      arguments: >-
        -p PublishProfile="DefaultContainer"
        -p ContainerRepository="my-repository"
        -p ContainerImageTags="\"$(Build.BuildNumber);latest\""
        -p Version="$(Build.BuildNumber)"

enter image description here

2
Ziyang Liu-MSFT On

You can try to use -p ContainerImageTags="'\"$(Build.BuildNumber);latest\"'".

In the log, I can see the following:

enter image description here