Home > Blockchain >  Execute azure command in powrershell without writing error to console?
Execute azure command in powrershell without writing error to console?

Time:10-30

I am using powershell script in pipeline and the problem I have with this query.

$value = $(az appconfig kv show -n ThisisEnv --key thisisconfigkey) | ConvertFrom-Json

What this query does is get the data related to key if exist. If this key doesn't exist it give the error like

ERROR: Key 'abcdefg' with label 'None' does not exist.

It is work as expected. In pipeline when the key doesn't exist, it's printed a error on CLI. The pipeline see it as error and show it as failed. Is there a way I can make it work.

Is there a way I can stop it printing it on console. Any powershell operator which help me to get the value from azure command but also let me get it without print anything on console.

CodePudding user response:

You could try to redirect the standard error using 2> $null

$value = $(az appconfig kv show -n ThisisEnv --key thisisconfigkey 2> $null) | ConvertFrom-Json

This will suppress the error within the console. You might also want to set the powerShellIgnoreLASTEXITCODE within the Azure CLI Task in order that the pipeline run doesn't fail - or as a workaround, set the $LASTEXITCODE to 0

  • Related