microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.19k stars 924 forks source link

Pipeline parameters from template are not rendered in Run pipeline UI #570

Open jvmlet opened 2 years ago

jvmlet commented 2 years ago
.azure-pipelines.yml
extends: 
   template: template.yml
   parameters:
     test: ${{ parameters.test }}
.template.yml
parameters:
  - name: test
    default: "false"
    type: boolean

image

matteotumiati commented 2 years ago

This is expected, you have to define runtime parameters in the main pipeline '.azure-pipelines.yml'. I would say it's an architectural design choice, not a bug.

jvmlet commented 2 years ago

Thanks @matteotumiati. Any chance to get what I'm after? Like template for variables?

matteotumiati commented 2 years ago

Depends a little bit on what you are after 😄

Let's assume you have a template repository, where you store all the templates and the project repository, where you have the "real" pipeline.

template repo
  ├── template-1.yml
  ├── template-2.yml
  └── variables.yml

project repo
  ├── ...
  └── azure-pipelines.yml

You could have one or more templates into the template repository, including a variables.yml file, structured in this way:

variables:
- name: variablename
  value: variableValue

In any of the templates you can refer to the variables using:

# template-1.yml
variables:
- template: variables.yml
....
steps:
...

Or you can reference the same file in the project repository:

# azure-pipelines.yml
resources:
  repositories:
    - repository: my-template-repository
      type: git
      name: project-name/my-template-repository

variables:
  - template: template-1.yml@my-template-repository

steps:
  ...
jvmlet commented 2 years ago

We have X repositories that use template to define the pipeline. When running manually, set of parameters should be presented and passed to templates jobs

matteotumiati commented 2 years ago

As far as I know there's no possibility to have either variables or runtime parameters to be "available" only when running manually. I would say you always need to provide a default value that a user can change when running the pipeline manually.

My recommendation is to go with variables.. slightly less user friendly compared to runtime parameters (but not more complicated to set when opening the build dialog), but you can override the values from REST APIs, if needed, or create templates as shown above.

With runtime parameters you cannot have templates and these must be defined on top of each pipeline, which means you will have to duplicate them X times, depending on how many repos will be using the same parameters.

jvmlet commented 2 years ago

Thanks @matteotumiati, I will leave the issue open, may be MS team will find this feature useful to implement