skip to Main Content

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?

2

Answers


  1. 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

    Login or Signup to reply.
  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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search