-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added try catch block added for azlogin #10556
base: main
Are you sure you want to change the base?
Conversation
@@ -240,13 +240,19 @@ Function GenerateResourcesAndImage { | |||
|
|||
try { | |||
# Login to Azure subscription | |||
try { | |||
$azAccount = az account show -o none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where azAccount
variable is used? Why do we need it?
az account show -o none
always returns nothing because -o none
means --output none
. What do we expect to set to azAccount
variable?
@@ -240,13 +240,19 @@ Function GenerateResourcesAndImage { | |||
|
|||
try { | |||
# Login to Azure subscription | |||
try { | |||
$azAccount = az account show -o none | |||
Write-Warning "Already logged in..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it warning? It looks like expected behaviour for me. Should it be Write-Verbose
?
@@ -240,13 +240,19 @@ Function GenerateResourcesAndImage { | |||
|
|||
try { | |||
# Login to Azure subscription | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script will never enter catch
block because az account show -o none
command will never throw exception.
Please check other places in this script to see how to handle command output correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxim-lobanov this is not correct, the az account show -o none
gives error if not logged in.
Easy to reproduce locally:
az logout
az account show -o none
No subscription found. Run 'az account set' to select a subscription.
See my comment here why it would never get into the catch
block
Edit: Maybe I misunderstood, if you meant the command is not causing exception to enter the catch
block but you are aware it still produces error in the outputs if not logged in.
try { | ||
$azAccount = az account show -o none | ||
Write-Warning "Already logged in..." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please follow PowerShell styleguide as it is recommended in this repo readme? See https://github.com/actions/runner-images/blob/main/CONTRIBUTING.md for more details on correct style.
}
andcatch
should be on the same line- content of
catch
block should have different indentation fromcatch
block itself.
I just wanted to add here that the current approach here for this When not logged in you will get the following:
It happens because the Powershell In #10602 I have solved this using the following way:
The |
This PR adds a try-catch block for the
azlogin
function. * If an account is already logged in, it prints a warning message "Already logged in...". * If the login fails, it prints an error message "Login failed...". This change will help to handle the login process more gracefully and provide better user feedback.Related issue:
#10236
Check list