Azure Pipeline Parameter List of Strings and Pipeline Configuration

Author

Reads 515

Woman in focus working on software development remotely on laptop indoors.
Credit: pexels.com, Woman in focus working on software development remotely on laptop indoors.

Working with Azure Pipelines can be a bit tricky, especially when it comes to configuring parameters. One thing to keep in mind is that Azure Pipelines supports a list of strings as a parameter type.

In Azure Pipelines, a list of strings is a type of parameter that allows you to pass multiple values to a pipeline. This can be useful for scenarios where you need to iterate over a list of values.

To configure a list of strings in Azure Pipelines, you need to specify the type as "string" and use the "[] " notation to indicate that it's a list. For example, you can define a parameter like this: `parameters - name: colors - type: string - default: ['red', 'green', 'blue']`.

Azure Pipelines also allows you to configure the default value for a list of strings parameter, which can be useful for scenarios where you want to provide a default set of values.

Defining a Pipeline

Credit: youtube.com, What is a parameter in Azure pipeline? | Advanced parameter usage in Azure DevOps | CI/CD Tutorial

Defining a pipeline involves several key steps. You can set runtime parameters at the beginning of a YAML file.

To define a pipeline parameter, follow these steps: click on your pipeline to view its configuration tabs, select the "Parameters" tab, and click on the "+ New" button to define a new parameter. Enter a name and description for the parameter, and select its data type from the dropdown menu, which can be String, Int, Float, Bool, Array, Object, or SecureString.

Each parameter must specify a type, such as boolean, number, object, or string. You can provide a default value in the YAML by using the 'default' key, run the pipeline and provide a value manually at runtime, or if neither of the above options are used, then the first value listed in the 'values' key will be used.

You can also assign a default value to the parameter when defining it. The default value will be used if no other value is provided.

Here are the common types of parameters:

  • boolean
  • number
  • object
  • string

Note that pipeline parameters can be used to control the behavior of a pipeline and its activities.

Expressions

Credit: youtube.com, Fun with ADF Data Flow Expressions: String Interpolation & Parameters

Expressions can be used to create more complex scenarios in Azure Pipelines, especially when combined with parameters.

Expressions can be used to loop over steps or ignore steps, similar to setting the "condition" property to "false".

The "each" expression allows you to repeat steps with different parameters, while the "if" expression enables conditional execution of steps.

The boolean function "eq" can be used in conjunction with the "if" expression to compare values.

You can pass in different "TrainingSteps" for each scenario, as demonstrated in the template file example.

This allows you to have a single template with multiple scenarios, where only the training steps differ.

Expressions can also be used to inject steps, making it easier to manage complex workflows.

By using expressions, you can create reusable templates that adapt to different scenarios and parameters.

Curious to learn more? Check out: Create Task Group Azure Devops

Pipeline Tasks

In Azure Pipelines, you can dynamically include a list of steps in the build process using the stepList parameter.

The main pipeline (azure-pipelines.yml) defines two jobs: build and deploy. The build job uses a template (build.yml) and passes a list of build tasks using the stepList parameter.

The build.yml template sets the .NET Core SDK to 6.x. It iterates over each step in the build_tasks parameter and executes each step defined in the build_tasks list.

Include List of Steps

Credit: youtube.com, Task Pipeline

Including a list of steps in your pipeline tasks can be a game-changer for complex build processes. This approach allows you to dynamically include tasks as needed, making your pipeline more flexible and efficient.

You can use the stepList parameter to achieve this. For example, in the main pipeline (azure-pipelines.yml), you can define two jobs: build and deploy.

The build job uses a template (build.yml) and passes a list of build tasks using the stepList parameter. This list can be used to dynamically include steps in the build process.

Here's an example of how the build.yml template can be set up:

  • Defines the parameter build_tasks with the stepList type and a default empty list.
  • Sets the .NET Core SDK to 6.x.
  • Iterates over each step in the build_tasks parameter.
  • Executes each step defined in the build_tasks list.

Pass Conditional Task Arguments

You can use if statements to call tasks or templates with different configurations. This is useful when your pipeline needs to perform different actions based on certain conditions.

The sendMessage.yaml file can be designed to require a message parameter, which doesn't have a default value, and an optional displayName parameter that defaults to "Send message" if no other value is provided.

Credit: youtube.com, Task condition based on parameter - Azure DevOps

The condition parameter can be used to evaluate a condition in the if statement, and it can have an empty default value that evaluates to false. This condition definition is indented inside the if block.

Azure DevOps evaluates the template during pipeline initialization and receives the condition parameter as a string. This string is then placed in the generated end result.

You can create a simple pipeline to demonstrate this in practice by using a condition to skip a step if the previous step has failed.

The success message step can be explicitly defined with a condition, which improves readability. This condition is implicitly assumed when not defined, but defining it explicitly can make the pipeline easier to understand.

Pipeline Overview

You can set runtime parameters at the beginning of a YAML file in Azure Pipelines. This allows you to define parameters that can be used in your pipeline.

To use parameters in pipelines, you can specify a pool value in the jobs section that references the parameter used to run the job. For example, you can use a parameter like "image" with three hosted agents as string options.

A unique perspective: Azure Pipelines Parameters Types

Credit: youtube.com, Part 22- How to use parameters in azure YAML CI/CD pipelines |

Pipeline parameters can be used to control the behavior of a pipeline and its activities. They can be defined at the pipeline level and cannot be modified during a pipeline run.

If you don't make a selection for a parameter like "image" when manually triggering your pipeline to run, the default option will be used. In this case, the default option is "ubuntu-latest".

Francis McKenzie

Writer

Francis McKenzie is a skilled writer with a passion for crafting informative and engaging content. With a focus on technology and software development, Francis has established herself as a knowledgeable and authoritative voice in the field of Next.js development.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.