2

In a Azure Devop Build, I'm using a tool(https://github.com/tomchavakis/nuget-license). I want this tool to be installed in my Azure Devop Agent.

I've created this task in my YML:

  - task: CmdLine@2
    displayName: 'Install dotnet-project-licenses'
    inputs:
        script: 'dotnet tool install dotnet-project-licenses -g'

This works, but only the first time. Then when the tool is already installed, I get an error code.

So how to install this automatically on my agents once? Or swallow the error?

J4N
  • 19,480
  • 39
  • 187
  • 340

2 Answers2

4

Try running the script as

dotnet tool update dotnet-project-licenses -g

If the tool isn't installed this command should install it, and if it is already installed it shouldn't give an error

DavidCox88
  • 813
  • 1
  • 10
2

You can add a powershell task instead of the cmd and add the continue on error action. Then your pipeline will continue if it is already installed.

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'dotnet tool install dotnet-project-licenses -g'
    errorActionPreference: 'continue'

enter image description here

GeralexGR
  • 2,973
  • 6
  • 24
  • 33
  • Thank you, it's a great approach even if I've been able to totally remove the error with @DavidCox88 approach. – J4N Jul 13 '22 at 11:36