Skip to content

Commit 4d00048

Browse files
update Azure login handling in resource deployment script
1 parent 34bf7bc commit 4d00048

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- main # Adjust this to the branch you want to trigger the deployment on
66
- dev
77
- demo
8+
- hb-script-fix
89
schedule:
910
- cron: "0 10,22 * * *" # Runs at 10:00 AM and 10:00 PM GMT
1011

Deployment/resourcedeployment.ps1

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,23 @@ function PromptForParameters {
102102
$params = PromptForParameters -email $email
103103
$email = $params.email
104104

105+
$script:alreadyLoggedIn = $false
106+
105107
function LoginAzure([string]$tenantId, [string]$subscriptionID) {
106108
Write-Host "Log in to Azure.....`r`n" -ForegroundColor Yellow
109+
if ([string]::IsNullOrEmpty($tenantId) -or [string]::IsNullOrEmpty($subscriptionID)) {
110+
az login
111+
if ($LASTEXITCODE -ne 0) {
112+
Write-Host "Failed to log in to Azure. Please check your credentials." -ForegroundColor Red
113+
failureBanner
114+
exit 1
115+
}
116+
else{
117+
Write-Host "Logged in to Azure successfully." -ForegroundColor Green
118+
$script:alreadyLoggedIn = $true
119+
return
120+
}
121+
}
107122
if ($env:CI -eq "true"){
108123
az login --service-principal `
109124
--username $env:AZURE_CLIENT_ID `
@@ -478,13 +493,16 @@ try {
478493

479494
# Map the deployment result to DeploymentResult object from .env file
480495
if ($ResourceGroupName) {
496+
LoginAzure "" ""
481497
$deploymentResult.MapResultAz($ResourceGroupName.Trim())
482498
}
483499
else {
484500
$deploymentResult.MapResultAzd()
485501
}
486502

487-
LoginAzure $deploymentResult.TenantId $deploymentResult.SubscriptionId
503+
if (-not $script:alreadyLoggedIn) {
504+
LoginAzure $deploymentResult.TenantId $deploymentResult.SubscriptionId
505+
}
488506

489507
# Display the deployment result
490508
DisplayResult($deploymentResult)

0 commit comments

Comments
 (0)