Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass array as inputs to Azure DevOps YAML task

I'm trying to configure a CI that will produce NuGet packages as artifacts on Azure DevOps (that will be later pushed to my NuGet server).

For this, I'm using Builds Pipelines on Azure DevOps, the YAML version.

I have 3 projects that should build packages. I'm using NuGetCommand@2 to accomplish this task :

- task: NuGetCommand@2
  inputs:
    command: pack
    packagesToPack: $(Build.SourcesDirectory)/src/HTS_MessageEngine.Communication/HTS_MessageEngine.Communication.csproj
    majorVersion: $(majorVersion)
    minorVersion: $(minorVersion)
    patchVersion: $(patchVersion)
    versioningScheme: byPrereleaseNumber

However, I have to duplicate this block 3 times, for each project. Is there a way to specify an array of projects in the packagesToPack parameter? So far, the version is the same for each package, so I don't need three different blocks...

Note: these 3 projects are all 3 NetStandard and properties for package building are stored in csproj directly

like image 717
cdie Avatar asked Feb 05 '19 19:02

cdie


People also ask

How do you pass variables in Azure pipelines YAML tasks?

Passing variables between tasks in the same job Set the value with the command echo "##vso[task. setvariable variable=FOO]some value" In subsequent tasks, you can use the $(FOO) syntax to have Azure Pipelines replace the variable with some value.

How do you use variable groups in Azure DevOps YAML?

To use a variable group, open your pipeline. Select Variables > Variable groups, and then choose Link variable group. In a build pipeline, you see a list of available groups. In a release pipeline, for example, you also see a drop-down list of stages in the pipeline.

Does Azure pipelines support coding through YAML?

In this article, you'll learn how to set up and run your canvas app tests built in the Test Studio by using a YAML pipeline in Azure DevOps Services. You can use a public project on GitHub—Microsoft/PowerAppsTestAutomation—to: Automate the operations of signing in to your application.


2 Answers

For above code I got this exception running a build:

my-template.yml (Line: 1, Col: 12): Unexpected value ''

but this works for me:

# my-template.yml
parameters:
- name: projects
  type: object
  default: {}
steps:
- ${{ each project in parameters.projects }}:
  - task: PublishBuildArtifacts@1
    displayName: 'Publish ${{ project }}
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ project }}.zip'

and then:

# ci.yml
steps:
- template: my-template.yml
  parameters:
    projects:
    - test1
    - test2
like image 134
Krzysztof Madej Avatar answered Oct 08 '22 13:10

Krzysztof Madej


you can use each function (if its available at all at this point in time):

# my-template.yml
parameters:
steps:
- ${{ each project in parameters.projects }}:
  - task: PublishBuildArtifacts@1
    displayName: Publish ${{ project }}
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ project }}.zip'
# ci.yml
steps:
- template: my-template.yml
  parameters:
    projects:
    - test1
    - test2

Github PR for this functionality: https://github.com/Microsoft/azure-pipelines-yaml/pull/2#issuecomment-452748467

like image 34
4c74356b41 Avatar answered Oct 08 '22 13:10

4c74356b41