I'm trying to create a pipeline to run swagger-codegen for each Swagger document in a repo. I'd like to avoid having to keep the pipeline yaml updated for each API specification we generate. For most stages of this process, it's enough to loop through them in Powershell. But for publishing nuget and npm packages, it would be a lot easier to call another template (or otherwise repeat a task) for each one. (Publishing to our Azure feed via powershell in a pipeline escapes me.)
I've had no trouble passing in an array when calling another template manually. I can generate a JSON string of an array of the file names. But, when I try to use this as a variable, or as a runtime expression, I get a compile error and the pipeline doesn't even run:
azure-pipelines.yml:
...
- task: PowerShell@2
name: getSpecFiles
inputs:
targetType: 'inline'
script: |
$SpecFiles = ConvertTo-Json -InputObject ([array] (get-item .\OpenApi\*.json | select -ExpandProperty Name)) -Compress # comes out to ["NotesAndTasks-1.json"]
$setSpecFileNames = '##vso[task.setvariable variable=specFileNames]' + $SpecFiles; # I've also tried specifying it's an output variable with no luck
Write-Output $SpecFiles
Write-Output $setSpecFileNames
displayName: 'Get list of spec files'
- template: generate-many-apis.yml
parameters:
# specFileNames: $(specFileNames)
# specFileNames: $[specFileNames]
specFileNames: ["NotesAndTasks-1.json"]
generate-many-apis.yml:
parameters:
- name: specFileNames
type: object
default: { }
steps:
- ${{ each value in parameters.specFileNames }}:
- task: PowerShell@2
displayName: Generate APIs
inputs:
targetType: 'inline'
script: |
Write-Output "${{ value }}" # not currently calling the generate-api task; just testing
What would it take to run the generate-api task once for each Swagger .json? Or am I better off figuring out how to publish my npm and nuget packages from a script task?
Also, I'm able to change the parameter of generate-many-apis to a string, and successfully pass it that way -- but then the ${{ each }} loop fails.