0

Template:

parameters:
- name: PathPrefix
  displayName: 'Path prefix'
  type: string
  default: ''

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: ${{parameters.PathPrefix}}**/$(Build.DefinitionName).sln

Pipeline:

resources:
  repositories:
  - repository: devops
    name: foo/devops
    type: git
    ref: master

trigger:
  branches:
    include:
    - refs/heads/*

jobs:
- job: Job_1
  displayName: Agent job 1
  pool:
    vmImage: windows-latest
  steps:
  - checkout: self
  - template: azure/pipelines/pipeline.yaml@devops
    parameters:
      PathPrefix: $(Build.DefinitionName)

Run error during the restore step:

##[error]No files matched the search pattern.

Even setting verbosityRestore: detailed on the restore step doesn't give me any more information.

If I don't set PathPrefix, it seems to use the default empty string and find the solution file (in some cases). However, if I do set the prefix, which is needed in some repos, it can't find the file. I've tried various ways of referencing the parameter within the template (${{}}, $(), $[] and others) and different ways of specifying it within the pipeline, including hard-coding the path (though I want to use the variable instead), but nothing works.

I thought maybe variables would work instead, so I also tried specifying variables in the pipeline and using them in the template, but that results in the same error. Defining the variable in the template gave me a compilation error for the template (unexpected token 'variable' or something similar).

Josh
  • 6,944
  • 8
  • 41
  • 64
  • A shot in the dark, have you tried adding quotes to escaping the special chars? `'${{parameters.PathPrefix}}**/$(Build.DefinitionName).sln'` – psfinaki May 21 '21 at 07:53

1 Answers1

0

Look at what you're passing and mentally expand the results.

${{parameters.PathPrefix}}**/$(Build.DefinitionName).sln

If Build.DefinitionName is foo, and you pass that in as PathPrefix, then what you get is:

foo**/foo.sln

It looks like you want an extra forward slash in there, so you get foo/**/foo.sln.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120