Scott Langham
Scott Langham

Reputation: 60311

Set build process parameters at queue time

I have defined a build definition and adding some tasks to it. When I manually queue a new build I would like to be able to provide the value for an input of one of the tasks.

I thought I might be able to achieve this by linking the task input to a process parameter, but it's only a slightly improvement. The process parameter shows up on the 'Process' section which as at the top when I edit the build definition, so it's a bit easier to find.

I had really been expecting when I linked the task input for it to be linked to a variable under the 'Variables' tab. Those variables can be ticked to allow them to be configured at queue time.

Interestingly when I linked the input to a process parameter it was given a name like "Parameters.TheTaskInputName". I also thought I might be able to define that under the Variables tab and make it settable at queue time and tried that. This doesn't seem to make any difference either.

Should this work, if so, what am I doing wrong? Or is it a missing feature I should be posting on visualstudio.uservoice.com?

Upvotes: 1

Views: 4770

Answers (2)

Moha Dehghan
Moha Dehghan

Reputation: 18443

How parameters and variables are passed to tasks

  • Parameters: All input parameters are passed to tasks as environment-variables, prepended with "INPUT_". You need to find the name of the parameter in the task (what you see in the pipeline edit page, is the title of the parameter, not its name). I'll talk about finding the name of the input-parameter later in this answer.

  • Variables: Pipeline variables are also passed to tasks as environment-variables, as exactly as how they are defined. It doesn't matter if the variable is defined in the pipeline, or added later when queuing the build.

How to find parameter names and values

You should find the tasks "task.json" file in. It is available in its source directory (You can also unpack the task's .vsix file). Since all the default tasks of Azure DevOps (developed by Microsoft) are available on Github, that's an easy thing to do.

Example

Let's change the value of parameter "Command" of the ".NET Core" task. It's "task.json" file is here. Look for "command" text in "inputs" section:

"inputs": [
    {
        "name": "command",
        "type": "pickList",
        "label": "Command",
        "defaultValue": "build",
        "required": true,
        "helpMarkDown": "The dotnet command to run. Select 'Custom' to add arguments or use a command not listed here.",
        "options": {
            "build": "build",
            "push": "nuget push",
            "pack": "pack",
            "publish": "publish",
            "restore": "restore",
            "run": "run",
            "test": "test",
            "custom": "custom"
        },
        "properties": {
            "EditableOptions": "False"
        }
    },

You can see that the parameter name is the same as its label (that's not always the case), and the values are "build", "push", "pack", ...

Now you can add a variable named input_command (case-insensitive) when queuing the build, and fill in the value there. This will override anything you set in the pipeline definition.

Passing parameter when queuing the build

The values of parameters are sent as strings, no matter what is the type of parameter. For example, boolean parameters may have a value of "true" or "false", and picklist parameters have a corresponding string value for each item in the picklist (like the example above).

For another example, let's look at the "NuGet restore" task. It has a "Verbosity" parameter in the "Advanced" section. Open the task.json file. Here is the relevant part:

    {
        "name": "verbosityRestore",
        "type": "pickList",
        "label": "Verbosity",
        "defaultValue": "Detailed",
        "helpMarkDown": "Specifies the amount of detail displayed in the output.",
        "required": "false",
        "groupName": "restoreAdvanced",
        "options": {
            "Quiet": "Quiet",
            "Normal": "Normal",
            "Detailed": "Detailed"
        }
    },

The parameter name is different for each "command" of the task. For restore command, it is "verbosityRestore".

Upvotes: 1

raterus
raterus

Reputation: 2089

Builds have "Process Variables", and you can control whether they are able to be set at Queue time.

Setup:

How to set up Process Variables

Setting at Queue Time:

Setting at Queue Time

Upvotes: 3

Related Questions