skip to Main Content

I am setting up an Azure pipeline and need to get a specific step to run multiple times based on the defined environments. I also need to replace a placeholder in a file with variable values and I need to have different value for each environment. What is the most straight forward way to achieve that?

2

Answers


  1. You can configure your task to run conditionally (when environmentname contains TEST, a certian variable is set to true etc…). Here you can see how to configure this -> https://www.bizstream.com/blog/custom-task-conditions-in-azure-pipelines/

    I assume you are running a release-Pipeline? If so you can create a variable with the same name multiple times but set different stages where the variable will apply to. See here for example -> https://crmchap.co.uk/working-with-variables-in-an-azure-devops-release-pipeline/ There is a variable ‘MySQLDBPassword’ defined with "Scope"="Release". You can add a second variable with the same name but set the scope to the Stage/Environment-Name you want this to work with

    Login or Signup to reply.
    1. If you are using classic build pipeline or release pipeline, you can use task groups.
      A task group allows you to encapsulate a sequence of tasks, already defined in a build or a release pipeline, into a single reusable task that can be added to a build or release pipeline, just like any other task. You can choose to extract the parameters from the encapsulated tasks as configuration variables, and abstract the rest of the task information. For more info about task group, please refer to Task groups for builds and releases (classic)

    2. If you are using YAML pipeline, you can use templates. Templates let you define reusable content, logic, and parameters. Templates function in two ways. You can insert reusable content with a template or you can use a template to control what is allowed in a pipeline. For more info about template, please refer to Template types & usage.
      If you want to pass different values to the template according to different environments, you can use Runtime parameters.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search