microsoft / azure-pipelines-tasks

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

After executing `dotnet tool install` command in a yml script for DevOps Pipelines, the installed tool is not found? #8291

Closed StefH closed 5 years ago

StefH commented 6 years ago

Environment

YML script

pool:
  vmImage: 'vs2017-win2016'

variables:
  buildConfiguration: 'Release'

steps:
- script: |
    dotnet tool install --global dotnet-sonarscanner
    dotnet sonarscanner begin /k:"***" /d:sonar.organization="***" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="%SONAR_TOKEN%" /v:"%BUILD_ID%"
    dotnet build ./src/***.csproj --configuration $(buildConfiguration)
    dotnet build ./test/***.csproj --configuration $(buildConfiguration)
    dotnet test ./test/***.csproj --configuration $(buildConfiguration) --framework net452 --logger trx --collect:"Code Coverage"
    dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%"

- task: PublishTestResults@2
  inputs:
    testRunner: VSTest
    testResultsFiles: '**/*.trx'

Issue Description

I get an error when using dotnet tool install --global *** in the new Azure Pipelines flow.

My command is like (see above YML file):

dotnet tool install --global dotnet-sonarscanner

This command outputs this:

Since you just installed the .NET Core SDK, you will need to reopen the Command Prompt window before running the tool you installed.
You can invoke the tool using the following command: dotnet-sonarscanner
Tool 'dotnet-sonarscanner' (version '4.3.1') was successfully installed.

And the next step will fail (running the above command in the same step or a different script step make no difference)

No executable found matching command "dotnet-sonarscanner"

How to solve this ?

cosmoKenney commented 5 years ago

I have the same problem. I am using a dotnet tool install for dotnet-xdt in one step. That succeeds. Then in a dotnet publish step, dotnet-xdt is executed via the csproj file. But the dotnet-xdt tool cannot be found.

I've tried to switch to a CMD step to do the dotnet tool install as per this issue: https://github.com/dotnet/cli/issues/8368#issuecomment-424852996, but it still does not work for me.

Last time I worked on this project was 8/20/18. And the unchanged pipeline worked then. But today it is no longer working and I haven't changed the csproj or the build pipeline.

bishal-pdMSFT commented 5 years ago

Please see this as a workaround.

bishal-pdMSFT commented 5 years ago

Created a new issue to handle this problem in Azure pipelines. Closing this issue.

cosmoKenney commented 5 years ago

Please see this as a workaround.

@bishal-pdMSFT, I don't know why you closed this. Per my comment above, the work around in (https://github.com/dotnet/cli/issues/8368#issuecomment-424852996) doesn't work for all global tools. I found that if you install a global tool in one pipeline step, then use it in another step, the tool will have been installed in some directory that the build is not happening in. So the tool still cannot be found.

bishal-pdMSFT commented 5 years ago

I have created a new issue for this. #8429 Created a new issue as that is applicable only when Dotnet core tool installer task in used. Azure pipelines cannot fix the scenario when an existing installation of dotnet is used - that has to be fixed by dotnet team.

vchirikov commented 5 years ago

It's confused situation, we can't use global tools, that well works in Appveyor for example.

wli3 commented 5 years ago

according to #8429, the fix is rolled out. @vchirikov do you mean this issue still repros?

vchirikov commented 5 years ago

@wli3 Yes, yesterday I got this error. I installed dotnet tool install -g Cake.Tool successfully, but in next step I do something like dotnet cake build/build.cake --target=Coverage and command failed with No executable found matching command "dotnet-cake" p.s. I don't like your task for install something, just use script

satrapu commented 5 years ago

I wanted to use both ReportGenerator and SonarScanner in my Azure DevOps pipeline and of course, I have encountered the infamous error "No executable found matching command ...".
Th only way I managed to install and use both of these tools was by installing a specific .NET Core SDK version via the DotNetCoreInstaller@0 task before hand:

- task: DotNetCoreInstaller@0
  displayName: Install .NET Core SDK
  name: install_dotnetcore_sdk
  enabled: true
  inputs:
    packageType: 'sdk'
    version: '2.1.500'

I'm not sure whether this approach covers any .NET Core tool, but it did the trick for me.

wli3 commented 5 years ago

I think the reason is only DotNetCoreInstaller@0 task will export the global tools path to PATH. And I do think putting extra in PATH by default need more discussion. Meanwhile you could export $HOME/.dotnet/tools or %USERPROFILE%\.dotnet\tools to PATH.

mykeels commented 4 years ago

If you're using bash, you could refresh its environment with one or more of the following commands:

. ~/.bashrc
. ~/.bashprofile
. ~/.profile
jabba2324 commented 4 years ago

To fix this I did the following after installing a tool using bash

    - script: |
          dotnet tool update -g #YOUR TOOL
          export PATH=$PATH:$HOME/.dotnet/tools
          . ~/.bashrc
          # RUN TOOL COMMAND HERE