dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.64k stars 1.05k forks source link

Installing tool to custom tool-path fails when trying to access it #10345

Closed vincentvanderwalt closed 4 years ago

vincentvanderwalt commented 5 years ago

I'm trying to install a custom tool during azure pipeline however if fails to pick up the tool. I've tried several options but they all fail at execution stage. I'm trying to use the tool-path because without it step 2 fails with cannot find the executable

Steps to reproduce

- task: DotNetCoreCLI@2
  displayName: 'Install Stryker'
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    vstsFeed: ${{ parameters.Build_Vsts_Feed }}
    arguments: 'install dotnet-stryker --tool-path ~/tools'
- script: |    
    cd ${{ parameters.Unit_Test_Folder }}
    dotnet ~/tools/stryker --project-file=${{ parameters.Stryker_Project }}.csproj
  displayName: 'Run Stryker tests against ${{ parameters.Stryker_Project }}'

Expected behavior

Tool should install and be executable

Actual behavior

Output from Installation task

sr/bin/dotnet tool install dotnet-stryker --tool-path ~/tools 
You can invoke the tool using the following command: dotnet-stryker |  
Tool 'dotnet-stryker' (version '0.11.0') was successfully installed.

Output from execution task No executable found matching command "dotnet-/home/vsts/tools/stryker"

No matter how i define tool-path it does the above behaviour of merging dotnet- to the path rather than /home/vsts/tools/dotnet-stryker

livarcocc commented 5 years ago

@wli3 can you take a look?

wli3 commented 5 years ago

dotnet ~/tools/stryker part should be the problem. You could either call it by dotnet stryker(need to be on PATH), or just directly call ~/tools/dotnet-stryker

vincentvanderwalt commented 5 years ago

@livarcocc @wli3

This issue isn't closed

I tried

~/tools/dotnet-stryker --project-file=${{ parameters.Stryker_Project }}.csproj

and the result is

/home/vsts/work/_temp/31079486-e89b-4a31-801f-5e4002bb8851.sh: line 2: /home/vsts/tools/dotnet-stryker: No such file or directory

can you please explain the path option?

I'm trying the tool-path because initially i tried without and got the following in the installation task

setup

- task: DotNetCoreCLI@2
  displayName: 'Install Stryker'
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    vstsFeed: ${{ parameters.Build_Vsts_Feed }}
    arguments: 'install -g dotnet-stryker'
- script: |    
    cd ${{ parameters.Unit_Test_Folder }}
    dotnet stryker --project-file=${{ parameters.Stryker_Project }}.csproj
  displayName: 'Run Stryker tests against ${{ parameters.Stryker_Project }}'

Result

in installation task

Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed. |  
You can invoke the tool using the following command: dotnet-stryker |  
Tool 'dotnet-stryker' (version '0.11.0') was successfully installed.

and this in the execution task

No executable found matching command "dotnet-stryker"

wli3 commented 5 years ago

--tool-path will install the tool in the specific location instead of installing it globally. It is recommended for CI, since this can avoid changing the machine state.

Let me keep keep checking why it failed

wli3 commented 5 years ago

Looks like arguments: 'install dotnet-stryker --tool-path ~/tools' will not expend ~ like normal shell would. I tried the following, it worked. I'll file an issue for why this won't work to Azdo. However, I think to use $(Agent.BuildDirectory) would be more reliable. Since you have the write access for sure

steps:
- task: DotNetCoreCLI@2
  displayName: 'Install Stryker'
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    arguments: 'install dotnet-stryker --tool-path $(Agent.BuildDirectory)/tools'

- script: |    
    ls $(Agent.BuildDirectory)/tools
  displayName: 'ls '

- script: |    
    $(Agent.BuildDirectory)/tools/dotnet-stryker --help
  displayName: 'Run Stryker tests against --help'
wli3 commented 5 years ago

filed here https://github.com/microsoft/azure-pipelines-tasks/issues/10731

vincentvanderwalt commented 5 years ago

@wli3 Thank you for the response. I can confirm it's now working for me. Much appreciated