Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

Using Azure DevOps Pipeline Variables in PowerShell Script Files

Using Azure DevOps Pipeline Variables in PowerShell Script Files
March 17, 2023 1 min read BEN ABT
AzureDevOps DevOps

This article was written in 2023. Versions, tools and recommendations may have changed since then. Newer posts are collected under DevOps.

Azure Pipelines inherently provides the ability for PowerShell scripts to be defined and executed inline.

PowerShell
1- task: AzureCLI@2
2  displayName: Bicep apply
3  inputs:
4    azureSubscription: MyAzureDevOpsConnectionName
5    scriptType: pscore
6    scriptLocation: inlineScript
7    inlineScript: az deployment group create --resource-group $(AZ_PLATFORM_RESOURCE_GROUP_NAME) --name $(AZ_DEPLOYMENT_NAME)-$(AZ_ENV_NAME) 

Unfortunately, this can become very confusing in many situations and also repetitive, since, for example, an Azure Bicep deployment task is required in several stages, so that the task is repeated accordingly.

It can help that the PowerShell script is no longer declared inline, but via a scriptPath.

PowerShell
1- task: AzureCLI@2
2  displayName: Bicep apply
3  inputs:
4    azureSubscription: MyAzureDevOpsConnectionName
5    scriptType: pscore
6    scriptLocation: scriptPath
7    inlineScript: $(Pipeline.Workspace)/bicep/run.ps1

What the script is missing now are the variables, whereby one must note that by default variables are available only within the file. This means that the variable $(AZ_PLATFORM_RESOURCE_GROUP_NAME).

To make variables available from outside in a PowerShell script file you need the $ENV: prefix.

PowerShell
1# run.ps1
2az deployment group create `
3  --resource-group $($ENV:AZ_PLATFORM_RESOURCE_GROUP_NAME) `
4  --name "$($ENV:AZ_DEPLOYMENT_NAME)-$($ENV:AZ_ENV_NAME)"

Now you can clean up your pipeline YAML file and reuse PowerShell commands very easily.

Related articles

How to migrate .NET versioning from x.x.x.x to SemVer

Jul 5, 2026 - 7 min read

How to migrate .NET versioning from x.x.x.x to SemVer

Many long-lived .NET repositories did not start with semantic versioning. They grew up with major.minor.build.revision, often set in …

Modern versioning for ASP.NET Core and web apps and how to produce idempotent artifacts

Jul 3, 2026 - 7 min read

Modern versioning for ASP.NET Core and web apps and how to produce idempotent artifacts

ASP.NET Core applications are usually released often enough that versioning stops being a documentation concern and turns into delivery …

Modern versioning for .NET desktop apps and how to produce idempotent artifacts

Jun 30, 2026 - 8 min read

Modern versioning for .NET desktop apps and how to produce idempotent artifacts

Desktop software makes versioning visible in a way that web systems often do not. A backend can hide a surprising amount of release …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026
Problem Details in ASP.NET Core and .NET 11

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026
Resilience in .NET with Microsoft.Extensions.Resilience

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026
What Matters in ASP.NET Core 11

What Matters in ASP.NET Core 11

Sep 14, 2026

Tags

.NET (192) Csharp (96) ASP.NET Core (48) Azure (41) DevOps (17) Docker (14) Microsoft (14) EF Core (11) Microsoft MVP (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Security (9) Synology (9) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7) Bicep (6)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact