Posts

Showing posts with the label Variables

How to deploy Bicep templates using Azure DevOps Pipelines

Image
In this article, I'm going to walk you through submitting Azure Deployments using Bicep files from Azure DevOps. Unfortunately, up until now, there is no official task for this need, so we are going to use Azure CLI instead. We'll start with creating a new pipeline, so open your project in Azure DevOps, switch to the Pipelines view, and hit the new pipeline button. We're going to use the classic edition for this demo, so go for the Use the classic editor option at the bottom. The first step of a build pipeline is to select the source that contains your code. For this, I've created a Git repository in the same project that contains a bicep file and looks like this: By default, the source repository is going to be set to Azure DevOps, which is fine for our case: Moving on to the next step, we're presented with some template options for the pipeline. We'll start with an empty pipeline that we'll build ourselves so click the Empty Job option. The next screen i...

Updates to the Foreach-Object-Parallel function

One of the most used functions of the CPolydorou.General module is "Foreach-Object-Parallel". This function allows us to execute PowerShell commands in parallel. This is accomplished by using new PowerShell runspaces and the most recent enhancement allows us to feed the runspaces with parameters. First, a quick example of the ForEach-Object-Parallel function. PS C:\> (0..5) | ForEach-Object-Parallel -MaxThreads 2 -ScriptBlock {$_; Start-Sleep -s 2} 0 1 2 3 4 5 This does not seem that much but if you execute the above command, you'll notice that the numbers appear in pairs due to the MaxThreads being set to "2". Each object passing the pipeline is being passed to the scriptblock of the Foreach-Object-Parallel function and can be accessed using the $_ variable. The issue here is that since the scriptblock is executed on another PowerShell runspace, all the variables of the original runspace are not available. Le...