From b5774fefc64299a79ea151019ad848d422bc409a Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Wed, 10 Sep 2025 18:19:34 +0100 Subject: [PATCH] Add support for a custom az-path --- action.yml | 3 +++ src/Cli/AzureCliLogin.ts | 7 +++++-- src/common/LoginConfig.ts | 15 +++++++++++++++ src/common/Utils.ts | 13 +++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 44c1f66a6..c46ef511d 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,9 @@ inputs: description: 'The type of authentication. Supported values are SERVICE_PRINCIPAL, IDENTITY. Default value is SERVICE_PRINCIPAL' required: false default: 'SERVICE_PRINCIPAL' + az-path: + description: 'Override the location of the Azure CLI program' + required: false branding: icon: 'login.svg' color: 'blue' diff --git a/src/Cli/AzureCliLogin.ts b/src/Cli/AzureCliLogin.ts index aa3a95ece..97b943468 100644 --- a/src/Cli/AzureCliLogin.ts +++ b/src/Cli/AzureCliLogin.ts @@ -7,6 +7,7 @@ import * as io from '@actions/io'; export class AzureCliLogin { loginConfig: LoginConfig; azPath: string; + azPathOverridden: boolean; loginOptions: ExecOptions; azVersion: string; @@ -17,7 +18,8 @@ export class AzureCliLogin { async login() { core.info(`Running Azure CLI Login.`); - this.azPath = await io.which("az", true); + this.azPath = this.loginConfig.azPath; + this.azPathOverridden = this.loginConfig.azPathOverridden; core.debug(`Azure CLI path: ${this.azPath}`); let output: string = ""; @@ -159,7 +161,8 @@ export class AzureCliLogin { silent?: boolean, execOptions: any = {}) { execOptions.silent = !!silent; - await exec.exec(`"${this.azPath}"`, args, execOptions); + const azPath = this.azPathOverridden ? this.azPath : `"${this.azPath}`; + await exec.exec(azPath, args, execOptions); } } diff --git a/src/common/LoginConfig.ts b/src/common/LoginConfig.ts index b9939c588..8631fe982 100644 --- a/src/common/LoginConfig.ts +++ b/src/common/LoginConfig.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import * as io from "@actions/io"; export class LoginConfig { static readonly AUTH_TYPE_SERVICE_PRINCIPAL = "SERVICE_PRINCIPAL"; @@ -25,6 +26,8 @@ export class LoginConfig { enableAzPSSession: boolean; audience: string; federatedToken: string; + azPath: string; + azPathOverridden: boolean; async initialize() { this.environment = core.getInput("environment").toLowerCase(); @@ -41,11 +44,23 @@ export class LoginConfig { this.audience = core.getInput('audience', { required: false }); this.federatedToken = null; + await this.getAzPath(); this.mask(this.servicePrincipalId); this.mask(this.servicePrincipalSecret); } + private async getAzPath(): Promise { + this.azPath = core.getInput('az-path', { required: false }); + if (this.azPath) { + this.azPathOverridden = true + return; + } + + this.azPath = await io.which('az', true); + this.azPathOverridden = false + } + private readParametersFromCreds() { let creds = core.getInput('creds', { required: false }); if (!creds) { diff --git a/src/common/Utils.ts b/src/common/Utils.ts index 8e9186d32..7c466121d 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -12,10 +12,19 @@ export function setUserAgent(): void { } export async function cleanupAzCLIAccounts(): Promise { - let azPath = await io.which("az", true); + let azPath = core.getInput('az-path', { required: false }); + let wrap = false + if (!azPath) { + azPath = await io.which('az', true); + wrap = true + } + core.debug(`Azure CLI path: ${azPath}`); core.info("Clearing azure cli accounts from the local cache."); - await exec.exec(`"${azPath}"`, ["account", "clear"]); + if (wrap) { + azPath = `"${azPath}"`; + } + await exec.exec(azPath, ["account", "clear"]); } export async function cleanupAzPSAccounts(): Promise {