Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create additional pipeline steps based on a variable?

Is it possible in Azure Devops YAML pipelines to dynamically create additional steps based on some variable data (without creating our own plugin)

The thing is I see that I want to iterate through several directories, but I don't want to just lump it all in a single step since it makes it harder to scan through to find an error.

like image 610
Archimedes Trajano Avatar asked Nov 21 '25 15:11

Archimedes Trajano


1 Answers

Is it possible in Azure Devops YAML pipelines to dynamically create additional steps based on some variable data (without creating our own plugin)

No, Yaml pipelines(azure-pipeline.yml) are under Version Control. So what you want (for your original title) is to dynamically commit changes to the azure-pipeline.yml file when executing the pipeline. That's not a recommended workflow.

1.Instead you can consider using Azure Devops Conditions to dynamically enable/disable the additional steps.

  • Use a template parameter as part of a condition

  • Use the output variable from a job in a condition in a subsequent job

  • Or Use some predefined variables:

    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
    

2.If you're not using Conditions, you can check conditional template as Simon suggests above.

Also, both #1 and #2 can work with new feature runtime parameters.

3.However, if the dynamic variable you mean comes from the result of components = result of ls -1 $(Pipeline.Workspace)/components command, above tips won't work for this situation. For this you can try something like this:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      # some logic to run `components = result of ls -1 $(Pipeline.Workspace)/components` and determine whether to set the WhetherToRun=true.

      'Write-Host "##vso[task.setvariable variable=WhetherToRun]True"'

- task: CmdLine@2
  inputs:
    script: |
      echo Hello world
  condition: eq(variables['WhetherToRun'], 'True')
like image 144
LoLance Avatar answered Nov 24 '25 06:11

LoLance



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!