Posts

Showing posts with the label Variable

Passing information between Azure DevOps Pipelines using Powershell

Image
In this article, we are going to examine one of the possible ways to transfer information from an Azure DevOps build pipeline to a release pipeline. The goal is to pass variables with information created during the execution of the build pipeline to the release pipeline. To accomplish this, we are going to use Powershell to create a build artifact that will contain all the variables needed, and then we'll consume it from the release pipeline. Starting with the build pipeline, we'll be using the classic bicep deployment that has outputs. This is the information that we would like to have available in the release pipeline. Think of a WebApp that is created by the build pipeline and we need its resource group and name in order to publish our code to it. First, let's go through the steps of the build pipeline. We have three steps in total, the azure deployment, the conversion of its outputs to variables, and finally the creation of the artifact. There is nothing sophisticated a...

PowerShell and MS-DOS variables

The first question that comes to mind after reading the title is "What do MS-DOS variables have to do with PowerShell???". Well, although you may be working solely with PowerShell - just like myself - you will eventually come across a variable in a configuration file, registry key etc. that is going to contain an MS-DOS formatted variable. Let's take the physical path of an IIS web site for example: PS C:\> Get-Website -Name "Default Web Site" | % physicalpath %SystemDrive%\inetpub\wwwroot PS C:\> In order for this value to be usable within PowerShell, we'll probably need to expand the "SystemDrive" variable. Fortunately, .NET has the appropriate tool for us, the "ExpandEnvironmentVariables" function. Invoking the above function with a string that contains a variable will return a new string with the variable extended. We are going to use the website's physical path once more and this time we'll expand th...

Powershell Strings and Expressions

Image
Today's topic? PowerShell, Strings, Variable Expansion and Quotes! Let's start with the difference between the single and double quotes. When using single quotes, the dollar sign within a string doesn't get treated as a special character so the text following it does not get resolved to the corresponding variable as opposed to the double quotes. The "file" variable in the following examples holds the output object of the Get-Item cmdlet. Variable expansion within strings... Let me start with an example. We have an object that has multiple properties and we want to create a string using the value of one of those properties. We have to use double quotes since we want the variable to be resolved but the result isn't the desired one.   This is because PowerShell will replace the variable with it's string representation and the property will be interpreted as text. This is where the PowerShell expressions come into play. Enclosing the variabl...