Azure / azure-cli

Azure Command-Line Interface
MIT License
3.92k stars 2.89k forks source link

`az pipelines build queue` should allow passing of template parameters #17196

Open kartsm opened 3 years ago

kartsm commented 3 years ago

Is your feature request related to a problem? Please describe.

I have a build pipeline defined in an azure-pipelines.yml file that I would like to be able to launch with user inputs in the Azure DevOps web UI. We are anticipating turning this pipeline into something of a service catalog item for our internal IT organization.

What the UI and YAML call "parameters" seems to be the natural choice for soliciting and validating user inputs before the build is launched. (What the UI and YAML call "variables" do not actively solicit input, but if you look for them they are there.)

I was researching how to queue builds with both "parameters" and "variables" (as they are known in the Azure DevOps web UI; the builds get API appears to call them templateParameters and parameters respectively). az pipelines build queue appears to offer the setting of "variables" but not "parameters" in its help.

$ az version
{
  "azure-cli": "2.20.0",
  "azure-cli-core": "2.20.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {
    "azure-devops": "0.17.0"
  }
}
$ az pipelines build queue --help
This command is from the following extension: azure-devops

Command
    az pipelines build queue : Request (queue) a build.

Arguments
    --branch             : Branch to build. Required if there is not a default branch set up on the
                           definition. Example: refs/heads/master or master or refs/pull/1/merge.
    --commit-id          : Commit ID of the branch to build.
    --definition-id      : ID of the definition to queue. Required if --name is not supplied.
    --definition-name    : Name of the definition to queue. Ignored if --id is supplied.
    --detect             : Automatically detect organization.  Allowed values: false, true.
    --open               : Open the build results page in your web browser.
    --org --organization : Azure DevOps organization URL. You can configure the default organization
                           using az devops configure -d organization=ORG_URL. Required if not
                           configured as default or picked up via git config. Example:
                           https://dev.azure.com/MyOrganizationName/.
    --project -p         : Name or ID of the project. You can configure the default project using az
                           devops configure -d project=NAME_OR_ID. Required if not configured as
                           default or picked up via git config.
    --queue-id           : Queue Id of the pool that will be used to queue the build.
    --variables          : Space separated "name=value" pairs for the variables you would like to
                           set.
# ... rest of output omitted ...

Describe the solution you'd like

Please extend the az pipelines build queue command to pass "parameters" to the queued build. On the command line this might look like:

$ az pipelines build queue --definition-name quux-garply --variables foo=bar zot=blurfl --template-params corge=wibble wobble=baz

When I retrieve the build record I'd like to see something like:

$ az pipelines build show --id 123456
{
  "buildNumber": "20210303.6",
  "buildNumberRevision": 6,
  ...
  "parameters": {
    "foo": "bar",
    "zot": "blurfl"
  },
  ...
  "templateParameters": {
    "corge": "wibble",
    "wobble": "baz"
  },
  ...
}

The various help texts should be updated accordingly.

Describe alternatives you've considered

I have considered custom-crafting the appropriate HTTP requests with curl, and using the Azure DevOps Python SDK. In terms of long-term maintenance by humans, a solution in the CLI seems to be the best way to express intent. I consider it clearer than either hand-crafting a complex JSON request body or writing custom Python code.

Additional context

ghost commented 3 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @narula0781, @ashishonce, @romil07.

Issue Details
**Is your feature request related to a problem? Please describe.** I have a build pipeline defined in an `azure-pipelines.yml` file that I would like to be able to launch with user inputs in the Azure DevOps web UI. We are anticipating turning this pipeline into something of a service catalog item for our internal IT organization. What the UI and YAML call "parameters" seems to be the natural choice for soliciting and validating user inputs before the build is launched. (What the UI and YAML call "variables" do not actively solicit input, but if you look for them they are there.) I was researching how to queue builds with both "parameters" and "variables" (as they are known in the Azure DevOps web UI; the [builds get API](https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/get?view=azure-devops-rest-6.1) appears to call them `templateParameters` and `parameters` respectively). [az pipelines build queue](https://docs.microsoft.com/en-us/cli/azure/pipelines/build?view=azure-cli-latest#az_pipelines_build_queue) appears to offer the setting of "variables" but not "parameters" in its help. ``` $ az version { "azure-cli": "2.20.0", "azure-cli-core": "2.20.0", "azure-cli-telemetry": "1.0.6", "extensions": { "azure-devops": "0.17.0" } } $ az pipelines build queue --help This command is from the following extension: azure-devops Command az pipelines build queue : Request (queue) a build. Arguments --branch : Branch to build. Required if there is not a default branch set up on the definition. Example: refs/heads/master or master or refs/pull/1/merge. --commit-id : Commit ID of the branch to build. --definition-id : ID of the definition to queue. Required if --name is not supplied. --definition-name : Name of the definition to queue. Ignored if --id is supplied. --detect : Automatically detect organization. Allowed values: false, true. --open : Open the build results page in your web browser. --org --organization : Azure DevOps organization URL. You can configure the default organization using az devops configure -d organization=ORG_URL. Required if not configured as default or picked up via git config. Example: https://dev.azure.com/MyOrganizationName/. --project -p : Name or ID of the project. You can configure the default project using az devops configure -d project=NAME_OR_ID. Required if not configured as default or picked up via git config. --queue-id : Queue Id of the pool that will be used to queue the build. --variables : Space separated "name=value" pairs for the variables you would like to set. # ... rest of output omitted ... ``` **Describe the solution you'd like** Please extend the `az pipelines build queue` command to pass "parameters" to the queued build. On the command line this might look like: ``` $ az pipelines build queue --definition-name quux-garply --variables foo=bar zot=blurfl --template-params corge=wibble wobble=baz ``` When I retrieve the build record I'd like to see something like: ``` $ az pipelines build show --id 123456 { "buildNumber": "20210303.6", "buildNumberRevision": 6, ... "parameters": { "foo": "bar", "zot": "blurfl" }, ... "templateParameters": { "corge": "wibble", "wobble": "baz" }, ... } ``` The various help texts should be updated accordingly. **Describe alternatives you've considered** I have considered custom-crafting the appropriate HTTP requests with curl, and using the Azure DevOps Python SDK. In terms of long-term maintenance by humans, a solution in the CLI seems to be the best way to express intent. I consider it clearer than either hand-crafting a complex JSON request body or writing custom Python code. **Additional context**
Author: kartsm
Assignees: -
Labels: `DevOps`, `Pipelines`, `Service Attention`
Milestone: -
yonzhan commented 3 years ago

pipelines

clerik commented 3 years ago

I upvote for that feature.

We are determining a few things from template parameters like the environment. Right now, I can't use the cli since it will always use the default settings.

Any news on this?

yonzhan commented 3 years ago

pipelines service team should look into this.

DSpirit commented 3 years ago

Can someone show me the file of the pipelines commands? I could develop this, but somehow I can't find any files related to pipelines, builds or queueing.

mathiasgheno commented 2 years ago

Would be awesome this feature.

Any chance this feature be considered in the next versions?

DSpirit commented 2 years ago

This now actually works with the Azure DevOps extension mentioned here: https://github.com/Azure/azure-devops-cli-extension/issues/972

Usage is pretty easy: az pipelines run --name "<pipeline-name>" --parameters key=value --project "<project>"

rdepew commented 1 year ago

I've been using az pipelines build queue all along. I don't know if az pipelines run is new, or if it's always been there and I just didn't notice. +1 to @DSpirit for the tip.

Waitaminnit, it doesn't show up in the docs at https://docs.microsoft.com/en-us/cli/azure/service-page/azure%20pipelines?view=azure-cli-latest . No wonder I didn't notice it. Is it really newer than the docs, or just undocumented? EDIT: I stand corrected. There it is.