You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pipelines/scripts/cross-platform-scripting.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,21 +3,22 @@ title: Cross-platform scripting
3
3
description: Patterns for safe cross-platform scripting
4
4
ms.topic: conceptual
5
5
ms.assetid: 96b7da24-617e-4a58-b65f-040c374e60e2
6
-
ms.date: 09/11/2025
6
+
ms.date: 09/12/2025
7
7
monikerRange: '<= azure-devops'
8
+
#customer intent: As an Azure Pipelines user, I want to understand how cross-platform scripting works so I can easily support different build platforms in my pipelines.
If you use cross-platform development technologies such as .NET Core, Node.js, or Python, Azure Pipelines cross-platform build capabilities bring both benefits and challenges. This article describes how to use cross-platform scripts to run pipelines on Linux, macOS, and Windows machines.
15
+
Azure Pipelines can run pipelines on Linux, macOS, and Windows machines. If you use cross-platform development technologies like .NET Core, Node.js, or Python, these cross-platform build capabilities bring both benefits and challenges. For example, most pipelines include one or more scripts to run during the build process, but script syntax often differs over platforms.
15
16
16
-
For example, most pipelines include one or more scripts to run during the build process, but script syntax often differs over platforms. You can use an Azure Pipelines `script` step to ease writing cross-platform scripts. You can also use [conditions](../process/conditions.md) to target scripts to specific platforms.
17
+
This article explains how you can use cross-platform scripting to support different platforms. You can use an Azure Pipelines `script` step to ease writing cross-platform scripts. You can also use [conditions](../process/conditions.md) to target scripts to specific platforms.
17
18
18
19
## Script step
19
20
20
-
The `script` keyword is a shortcut for the [command line task](/azure/devops/pipelines/tasks/reference/cmd-line-v2), which runs Bash on Linux and macOS or cmd.exe on Windows.
21
+
The [script](../get-started/key-pipeline-concepts.md#scripts) keyword is a shortcut for the [command line task](/azure/devops/pipelines/tasks/reference/cmd-line-v2), which runs Bash on Linux and macOS or cmd.exe on Windows.
21
22
22
23
You can use `script` to easily pass arguments to a cross-platform tool. The `script` step runs in each platform's native script interpreter, Bash on macOS and Linux or cmd.exe on Windows. The following example uses a `script` step to call `npm` with a set of arguments.
23
24
@@ -42,9 +43,9 @@ steps:
42
43
43
44
## Environment variables
44
45
45
-
Command line, PowerShell, and Bash resolve environment variables differently. To access a system-provided value like PATH, you must use a different syntax per platform.
46
+
Command line, PowerShell, and Bash resolve [environment variables](../process/variables.md#environment-variables) differently. To access a system-provided value like PATH, you must use a different syntax per platform.
46
47
47
-
Azure Pipelines uses [macro syntax](../process/variables.md#understand-variable-syntax) as a cross-platform way to refer to variables at runtime. The variable expands before the platform's shell sees it.
48
+
Azure Pipelines uses [macro syntax](../process/variables.md#macro-syntax-variables) as a cross-platform way to refer to variables at runtime. Variables with macro syntax get processed before a task executes during runtime. The variable expands before the platform shell encounters it.
48
49
49
50
To use macro syntax in a pipeline, surround the variable name as follows: `$(<variable name>)`. The following cross-platform example script echoes the ID of the pipeline.
50
51
@@ -114,13 +115,13 @@ steps:
114
115
---
115
116
116
117
>[!NOTE]
117
-
>PowerShell is also an option for scripts. The `pwsh` shortcut runs PowerShell 7.x on macOS, Linux, or Windows. Agents must have PowerShell 7.x installed. [Microsoft-hosted agents](../agents/hosted.md) have PowerShell 7.x installed by default.
118
+
>PowerShell is also an option for scripts. The [pwsh](/azure/devops/pipelines/yaml-schema/steps-pwsh) shortcut runs PowerShell 7.x on macOS, Linux, or Windows. Agents must have PowerShell 7.x installed. [Microsoft-hosted agents](../agents/hosted.md) have PowerShell 7.x installed by default.
118
119
119
120
## Platform-based switching
120
121
121
-
It's best to avoid platform-specific scripting to prevent the extra work and error risk of duplicating pipeline logic. If you can't avoid platform-specific scripting, you can use `conditions` to detect the platform you're on.
122
+
Platform-specific scripting to duplicate pipeline logic causes extra work and increased error risk. But if you can't avoid platform-specific scripting, you can use [conditions](../process/conditions.md) to detect what platform you're on.
122
123
123
-
For example, to get the IP address of the build agent you use `ipconfig` on Windows, `ifconfig` on macOS, and `ip addr`on Ubuntu Linux. The following pipeline gets that information from agents on different platforms by using the `condition` parameter.
124
+
For example, to get the IP address of the build agent, you must use `ifconfig` on macOS, `ip addr` on Ubuntu Linux, and the `Get-NetIPAddress` cmdlet on Windows PowerShell. The following pipeline gets that information from agents on different platforms by using conditions.
1.For**Run this task**, select **Custom conditions**, and in the **Custom condition** field, enter `"eq( variables['Agent.OS'], 'Linux' )"`.
164
+
1.Expand**Control Options**, select **Custom conditions** for **Run this task**, and in the **Custom condition** field, enter `eq( variables['Agent.OS'], 'Linux' )`.
1.For the **Custom condition**, enter `"eq( variables['Agent.OS'], 'Darwin' )"`.
173
+
1.Expand **Control Options**, select **Custom conditions** for **Run this task**, and in the **Custom condition** field, enter `eq( variables['Agent.OS'], 'Darwin' )`.
For **Run this task**, select **Custom conditions**, and in the **Custom condition** field, enter `"eq( variables['Agent.OS'], 'Windows_NT' )"`.
184
+
1. Expand **Control Options**, select **Custom conditions** for **Run this task**, and in the **Custom condition** field, enter `eq( variables['Agent.OS'], 'Windows_NT' )`.
0 commit comments