Skip to content

Commit 82deb88

Browse files
authored
Support PowerShell in AzureCLI task [Major version update] (#11336)
* Support PowerShell in AzureCLI task [Major version update] * updated azureclitask.ts * Resolving PR comments * Resolving PR comments * minor update
1 parent 7497210 commit 82deb88

24 files changed

+1830
-0
lines changed

Tasks/AzureCLIV2/Readme.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Azure CLI
2+
3+
## Overview
4+
This task supports running [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/overview) commands on Cross platform agents running Windows, Linux or Mac.
5+
6+
### What's new in Version 2.0
7+
- Supports running PowerShell and PowerShell Core script.
8+
- PowerShell Core script works with Xplat agents (Windows, Linux or OSX), make sure the agent has PowerShell version 6 or more.
9+
- Powershell script works only with Windows agent, make sure the agent has PowerShell version 5 or below.
10+
11+
## Contact Information
12+
Please report a problem at [Developer Community Forum](https://developercommunity.visualstudio.com/spaces/21/index.html) if you are facing problems in making this task work. You can also share feedback about the task like, what more functionality should be added to the task, what other tasks you would like to have, at the same place.
13+
14+
## Pre-requisites for the task
15+
The following pre-requisites need to be setup in the target machine(s) for the task to work properly.
16+
17+
#### **Azure Subscription**
18+
To deploy to Azure, an Azure subscription has to be linked to Team Foundation Server or to Azure Pipelines using the Services tab in the settings section. Add the Azure subscription to use in the Build or Release Management definition by opening the Account Administration screen (gear icon on the top-right of the screen) and then click on the Services Tab.
19+
- For Azure Classic resources use 'Azure' endpoint type with Certificate or Credentials based authentication. If you are using credentials based auth, ensure that the credentials are for a [**work account**](https://azure.microsoft.com/en-in/pricing/member-offers/msdn-benefits-details/work-accounts-faq/) because Microsoft accounts like [**[email protected]**](https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/DeployAzureResourceGroup) or [**[email protected]**](https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/DeployAzureResourceGroup) are not supported.
20+
- For [ARM](https://azure.microsoft.com/en-in/documentation/articles/resource-group-overview/), use 'Azure Resource Manager' endpoint type, for more details follow the steps listed in the link [here](https://go.microsoft.com/fwlink/?LinkID=623000&clcid=0x409).
21+
22+
#### **Azure CLI**
23+
The task needs the Azure CLI version to be installed on the automation agent, and the details are available [here](https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/).
24+
If an agent is already running on the machine on which the Azure CLI is installed, ensure to restart the agent to ensure all the relevant environment variables are updated.
25+
26+
## Parameters of the task
27+
The task is used to run Azure CLI commands on Cross platform agents running Windows, Linux or Mac . The mandatory fields are highlighted with a *.
28+
29+
* **Azure Connection Type**\*: Specify Azure endpoint type, for Azure Classic resources use 'Azure' endpoint, for Azure ARM resources use 'Azure Resource Manager' endpoint. This parameter is shown only when the selected task version is 0.* as Azure CLI task v1.0 supports only Azure Resource Manager (ARM) subscriptions
30+
31+
* **Azure Subscription**\*: Select the Azure Subscription where the Azure CLI commands have to be executed. If none exists, then click on the **Manage** link, to navigate to the Services tab in the Administrators panel. In the tab click on **New Service Endpoint** and select **Azure Resource Manager** from the dropdown.
32+
33+
* **Script Type**\*: Select the type of script to be executed on the agent. Task supports four types: Batch / Shell / PowerShell / PowerShell Core scripts, default selection being empty. Select Shell/PowerShell Core script when running on Linux agent or Batch/PowerShell/PowerShell Core script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows)
34+
35+
* **Script Location**\*: Select the mode of providing the script. Task supports two modes: one as a Script Path to a linked artifact and another as an inline script, default selection being the "Script Path"
36+
37+
* **Script Path**\*: When using Windows based agent, specify the path to the .bat , .cmd , .ps1 script whereas when using Linux based agent, specify the path to the .sh , .ps1 script you want to run. The path must be a fully qualified path or a valid path relative to the default working directory. Note: You must also specify the respective script type in above field.
38+
39+
* **Inline Script**\*: Specify the script inline here. When using Windows based agent use batch or PowerShell or PowerShell Core scripting whereas use shell or PowerShell Core scripting when using Linux based agents. Note: You must also specify the respective script type in above field.
40+
41+
* **Script Arguments**: Specify arguments to pass to the script.
42+
43+
* **Working folder**: Specify the working directory in which you want to run the script. If you leave it empty, the working directory is the folder where the script is located.
44+
45+
* **Fail on standard error**: Select this check box if you want the build to fail if errors are written to the StandardError stream.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"loc.friendlyName": "Azure CLI",
3+
"loc.helpMarkDown": "[Weitere Informationen](http://go.microsoft.com/fwlink/?LinkID=827160)",
4+
"loc.description": "Hiermit werden Azure CLI-Befehle für ein Azure-Abonnement in einem Shell-Skript (bei Ausführung für einen Linux-Agent) oder einem Batchskript (bei Ausführung für einen Windows-Agent) ausgeführt.",
5+
"loc.instanceNameFormat": "Azure CLI $(scriptPath)",
6+
"loc.releaseNotes": "Neuigkeiten in Version 1.0:\n– Unterstützung der neuen Python-basierten Azure CLI 2.0\n– Funktioniert mit plattformübergreifenden Agents (Linux, macOS oder Windows)\n– Die Verwendung mit Azure CLI 1.0 (node.js-basiert) erfordert einen Wechsel zu Aufgabenversion 0.0\n– Einschränkungen:\n– Keine Unterstützung für klassische Azure-Abonnements. Azure CLI 2.0 unterstützt nur Azure Resource Manager-Abonnements (ARM).",
7+
"loc.group.displayName.advanced": "Erweitert",
8+
"loc.input.label.connectedServiceNameARM": "Azure-Abonnement",
9+
"loc.input.help.connectedServiceNameARM": "Wählen Sie ein Azure Resource Manager-Abonnement für die Bereitstellung aus.",
10+
"loc.input.label.scriptLocation": "Skriptspeicherort",
11+
"loc.input.help.scriptLocation": "Skripttyp: Dateipfad oder Inlineskript",
12+
"loc.input.label.scriptPath": "Skriptpfad",
13+
"loc.input.help.scriptPath": "Vollqualifizierter Pfad des Skripts (BAT oder CMD bei Verwendung des Windows-basierten Agents, SH bei Verwendung eines Linux-basierten Agents) oder ein Pfad relativ zum Standardarbeitsverzeichnis",
14+
"loc.input.label.inlineScript": "Inlineskript",
15+
"loc.input.help.inlineScript": "Sie können Ihre Skripts hier inline einfügen. Bei Verwendung eines Windows-Agents verwenden Sie ein Batchskript, bei Verwendung eines Linux-basierten Agents ein Shell-Skript. Verwenden Sie für Batchdateien das Präfix \"call\" vor jedem azure-Befehl. Sie können auch mithilfe von Argumenten vordefinierte und benutzerdefinierte Variablen an das Skript übergeben. \n\n Beispiel für Shell: az --version || az account show \n\n Beispiel für Batch: call az --version || call az account show",
16+
"loc.input.label.args": "Argumente",
17+
"loc.input.help.args": "An das Skript übergebenen Argumente",
18+
"loc.input.label.addSpnToEnvironment": "Auf Dienstprinzipaldetails im Skript zugreifen",
19+
"loc.input.help.addSpnToEnvironment": "Hiermit werden Dienstprinzipal-ID und -schlüssel des ausgewählten Azure-Endpunkts zur Ausführungsumgebung des Skripts hinzugefügt. Sie können diese Variablen in Ihrem Skript verwenden: \"$servicePrincipalId\", \"$servicePrincipalKey\" und \"tenandId\" .\n\nEine Berücksichtigung erfolgt nur, wenn der Azure-Endpunkt das Dienstprinzipal-Authentifizierungsschema aufweist.",
20+
"loc.input.label.useGlobalConfig": "Globale Azure CLI-Konfiguration verwenden",
21+
"loc.input.help.useGlobalConfig": "Bei Festlegung auf FALSE verwendet diese Aufgabe ein eigenes, separates [Azure CLI-Konfigurationsverzeichnis](https://docs.microsoft.com/de-de/cli/azure/azure-cli-configuration?view=azure-cli-latest#cli-configuration-file). Dieses Verzeichnis kann zum Ausführen von Azure CLI-Aufgaben in *parallelen* Releases verwendet werden.",
22+
"loc.input.label.cwd": "Arbeitsverzeichnis",
23+
"loc.input.help.cwd": "Das aktuelle Arbeitsverzeichnis, in dem das Skript ausgeführt wird. Wenn keine Angabe erfolgt, wird der Stamm des Repositorys (Build) oder der Artefakte (Release) verwendet, das \"$(System.DefaultWorkingDirectory)\" lautet.",
24+
"loc.input.label.failOnStandardError": "Fehler bei Standardfehler.",
25+
"loc.input.help.failOnStandardError": "Bei aktivierter Option kann diese Aufgabe nicht erfolgreich ausgeführt werden, wenn Fehler in den StandardError-Stream geschrieben werden. Deaktivieren Sie das Kontrollkästchen, um Standardfehler zu ignorieren, und bestimmen Sie den Status mithilfe von Exitcodes.",
26+
"loc.messages.ScriptReturnCode": "Skript wurde mit Rückgabecode beendet: %d",
27+
"loc.messages.ScriptFailed": "Skriptfehler: %s",
28+
"loc.messages.UnsupportedEndpointScheme": "Nicht unterstütztes Authentifizierungsschema für Dienstverbindung: Dienstprinzipal für AzureRM",
29+
"loc.messages.AzureSDKNotFound": "Azure CLI 2.x ist nicht auf diesem Computer installiert.",
30+
"loc.messages.FailedToLogout": "Beim Abmelden ist der folgende Fehler aufgetreten: %s",
31+
"loc.messages.LoginFailed": "Fehler bei der Azure-Anmeldung.",
32+
"loc.messages.MSILoginFailed": "Fehler bei der Azure-Anmeldung mit einer verwalteten Dienstidentität.",
33+
"loc.messages.AuthSchemeNotSupported": "Das Authentifizierungsschema \"%s\" wird nicht unterstützt.",
34+
"loc.messages.ErrorInSettingUpSubscription": "Fehler beim Festlegen des Abonnements.",
35+
"loc.messages.SettingAzureConfigDir": "AZURE_CONFIG_DIR-Umgebungsvariable wird festgelegt auf: %s",
36+
"loc.messages.SettingAzureCloud": "Aktive Cloud wird festgelegt auf: %s",
37+
"loc.messages.GlobalCliConfigAgentVersionWarning": "Für Agent-Versionen vor 2.115.0 kann nur die globale Azure CLI-Konfiguration verwendet werden."
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"loc.friendlyName": "Azure CLI",
3+
"loc.helpMarkDown": "[Learn more about this task](http://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV2/Readme.md) or [see the Azure CLI documentation](https://docs.microsoft.com/cli/azure/)",
4+
"loc.description": "Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerSheell Core/Batch script when running on Windows agent.",
5+
"loc.instanceNameFormat": "Azure CLI $(scriptPath)",
6+
"loc.releaseNotes": "What's new in Version 2.0:\n- Support for PowerShell and PowerShell Core script. \n- PowerShell Core works with cross-platform agents (Linux, macOS, or Windows), make sure the agent has PowerShell version 6 or more. \n- Powershell script works with only Windows agent, make sure the agent has PowerShell version 5 or below.",
7+
"loc.group.displayName.advanced": "Advanced",
8+
"loc.input.label.connectedServiceNameARM": "Azure subscription",
9+
"loc.input.help.connectedServiceNameARM": "Select an Azure resource manager subscription for the deployment",
10+
"loc.input.label.scriptType": "Script Type",
11+
"loc.input.help.scriptType": "Type of script: PowerShell/PowerShell Core/Bat/Shell script. Select Shell/PowerShell Core script when running on Linux agent or Batch/PowerShell/PowerShell Core script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows).",
12+
"loc.input.label.scriptLocation": "Script Location",
13+
"loc.input.help.scriptLocation": "Path to script: File path or Inline script",
14+
"loc.input.label.scriptPath": "Script Path",
15+
"loc.input.help.scriptPath": "Fully qualified path of the script(.ps1 or .bat or .cmd when using Windows based agent else .ps1 or .sh when using linux based agent) or a path relative to the the default working directory",
16+
"loc.input.label.inlineScript": "Inline Script",
17+
"loc.input.help.inlineScript": "You can write your scripts inline here. When using Windows agent, use PowerShell or PowerShell Core or batch scripting whereas use PowerShell Core or shell scripting when using Linux based agents. For batch files use the prefix \"call\" before every azure command. You can also pass predefined and custom variables to this script using arguments \n\n example for PowerShell/PowerShellCore/shell: \naz --version \naz account show \n\n example for batch:\ncall az --version \ncall az account show",
18+
"loc.input.label.scriptArguments": "Script Arguments",
19+
"loc.input.help.scriptArguments": "Arguments passed to the script",
20+
"loc.input.label.powerShellErrorActionPreference": "ErrorActionPreference",
21+
"loc.input.help.powerShellErrorActionPreference": "Prepends the line `$ErrorActionPreference = 'VALUE'` at the top of your powershell/powershell core script.",
22+
"loc.input.label.addSpnToEnvironment": "Access service principal details in script",
23+
"loc.input.help.addSpnToEnvironment": "Adds service principal id and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: `$servicePrincipalId`, `$servicePrincipalKey` and `$tenantId` in your script.\n\nThis is honored only when the Azure endpoint has Service Principal authentication scheme.",
24+
"loc.input.label.useGlobalConfig": "Use global Azure CLI configuration",
25+
"loc.input.help.useGlobalConfig": "If this is false, this task will use its own separate [Azure CLI configuration directory](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest#cli-configuration-file). This can be used to run Azure CLI tasks in *parallel* releases",
26+
"loc.input.label.cwd": "Working Directory",
27+
"loc.input.help.cwd": "Current working directory where the script is run. Empty is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory)",
28+
"loc.input.label.failOnStandardError": "Fail on Standard Error",
29+
"loc.input.help.failOnStandardError": "If this is true, this task will fail when any errors are written to the StandardError stream. Unselect the checkbox to ignore standard errors and rely on exit codes to determine the status",
30+
"loc.input.label.powerShellIgnoreLASTEXITCODE": "Ignore $LASTEXITCODE",
31+
"loc.input.help.powerShellIgnoreLASTEXITCODE": "If this is false, the line `if ((Test-Path -LiteralPath variable:\\LASTEXITCODE)) { exit $LASTEXITCODE }` is appended to the end of your script. This will cause the last exit code from an external command to be propagated as the exit code of powershell. Otherwise the line is not appended to the end of your script.",
32+
"loc.messages.ScriptReturnCode": "Script exited with return code: %d",
33+
"loc.messages.ScriptFailed": "Script failed with error: %s",
34+
"loc.messages.UnsupportedEndpointScheme": "Unsupported service connection authorization scheme: Service Principal for AzureRM",
35+
"loc.messages.AzureSDKNotFound": "Azure CLI 2.x is not installed on this machine.",
36+
"loc.messages.FailedToLogout": "The following error occurred while logging out: %s",
37+
"loc.messages.LoginFailed": "Azure login failed",
38+
"loc.messages.MSILoginFailed": "Azure login failed using Managed Service Identity",
39+
"loc.messages.AuthSchemeNotSupported": "Auth Scheme %s is not supported",
40+
"loc.messages.ErrorInSettingUpSubscription": "Error in setting up subscription",
41+
"loc.messages.SettingAzureConfigDir": "Setting AZURE_CONFIG_DIR env variable to: %s",
42+
"loc.messages.SettingAzureCloud": "Setting active cloud to: %s",
43+
"loc.messages.JS_InvalidFilePath": "Invalid file path '%s'.",
44+
"loc.messages.JS_InvalidErrorActionPreference": "Invalid ErrorActionPreference '%s'. The value must be one of: 'Stop', 'Continue', or 'SilentlyContinue'",
45+
"loc.messages.GlobalCliConfigAgentVersionWarning": "For agent version < 2.115.0, only global Azure CLI configuration can be used"
46+
}

0 commit comments

Comments
 (0)