deleting and purging from keyvault using the azure cli capturing error messages - powershell

Im using AzureCLI#2 in devops to execute (via powershell) cli commands to first delete and then purge.
If you delete a cert from the keyvault you cannot purge it until it is fully deleted.
The error handling is wierd with the CLI (you cant use try/catch (See https://rajbos.github.io/blog/2019/07/12/Azure-CLI-PowerShell)
An error messsage is produced when the item is still deleting and ALSO when the item has been purged.
I need to know the difference between these two scenarios. Any idea how I can actually get the error message?

If the azure cli command failed, you can find the error message on the log of task AzureCLI#2. Through it isnot output to the error stream in the task log. See below screenshot.
You can set the attribute failOnStandardError to true. And the errors will be output to the error stream in the log.
As the blog you mentioned pointed out try/catch is not working with azure cli, since azure cli commands are not designed for Powershell. You can also write to the error stream an error message just to indicate where the actual error message resides in the log: See below:
$output = az keyvault key delete --name keyName --vault-name ..
if(!$output){
Write-Host "[Error] Error in deleting key keyName"
}

Related

Rundeck jobs fail when powershell script hits any error. NonZeroResultCode

Rundeck 4.8.0 community version on Redhat 9 Linux with Windows node.
My Rundeck jobs call powershell (.ps1) scripts on the windows node.
If there are any errors encountered in the script, the Rundeck job dies.
The rundeck output gives the NonZeroResultCode message
NonZeroResultCode: [WinRMPython] Result code: 1
There's more code that needs to be run after where the error occurred, but Rundeck just dies and doesn't continue the rest of the .ps1.
I previously used Rundeck version 3.something, I thing it was 3.9.
If there was an error in the script, such as a get or a set failed, the Rundeck console would just display the text of the error in red, and continue.
Now I know I can change my code and add try/catch statements, -erroraction SilentlyContinue and so on. However it makes no sense to me that Rundeck takes it upon itself to kill my script because a get or a set failed.
I want to be the one to decide if I want to exit the script or not, I don't want Rundeck to make that decision.
Can this behavior be changed?
thanks in advance.
That's the default Rundeck behavior.
You can "attach" an error handler on that script-step (on any step actually), e.g: the error handler could be the script code when your step fails.
The error handler feature is designed for that kind of scenario, take a look at this.

How to track installer script in a pipeline not executing?

I'm new to the whole Azure DevOps world and just got transferred to a new team that does just that.
One of my assignments is to fix an issue with a pipeline where one of the steps runs a shell script that installs an application. Currently, the step seems to run without any issue shown on the log, but when we connect to the container's pod, the app is not there.
If we run the script directly inside the pod, the application is installed correctly. I'm not sure how to track this. One of the things I've tried was to check the event log to see if there's any error while the installation is executed:Get-Eventlog -LogNmae "Windows PowerShell" -Newest 20, so far no luck here. Again, kinda of new at this, not sure what other tools are out there to track the reason why the script is not installing during the pipeline execution.
To troubleshoot your pipeline run, you can configure your pipeline logs to be more verbose.
1, To configure verbose logs for a single run, you can start a new build by choosing Run pipeline and selecting Enable system diagnostics, Run.
2,To configure verbose logs for all runs, you can add a variable named system.debug and set its value to true.
You can also try logging into your agent server and check for the event log. See this blog for view event log on windows.
The issue was related to how the task was awaited. Adding this piped params helped us solve the issue:
RUN powershell C:\dev\myprocess.ps1 -PassThru | Wait-Process;

Access to an API on Powershell does not work

I started to use the API on the PowerShell by instruction https://automation.deepsecurity.trendmicro.com/article/12_0/set-up-cookbook?platform=on-premise under API Cookbook - > Set up to use Bash or Powershell - to extract the managed agents status from the Deep Security.
I followed the instruction to test the access to the API on the Windows PowerShell using a pre-created API key, secret, headers and Invoke-WebRequest.
The documentation says if you receive the error message “The underlying connection was closed: An unexpected error occurred on a send” need to restart the PowerShell and repeat the test. But it does not work.
Can you please help with the automation on Powershell to successfully complete the test?

Jenkins job log monitoring, parsing with error pattern in master

I am working on a perl script which will do the following:
Trigger a script in post build action when job fails.
Read the log file and try to match the errors with a consolidated error/solution file.
If error is matched with pattern file, then concatenate the error message with the solution at the end of log file.
I am facing following challenges:
All jobs are running in Slave but the error log file is stored in Master. How can I run the script in post-build action? The script path will be taken from slave but my script is located in master. Is there any workaround for this?
The path of the error log is - /home/jenkins/data/jobs//builds/BUILD_NUMBER/log
We have many jobs that have folders created by jenkins folder plugins…how do we set the common folder for these?
/home/jenkins/data/jobs/FOLDERX//builds/BUILD_NUMBER/log
Other questions -
Do you think that publishing the jenkins error log and displaying the solution is the right approach?
There is no information on how complex the pattern maching is, but if it is a simple line based regex match there is a plugin for that, called Build Failure Analyzer.

powershell use-azurehdinsightCluster specified method not suppored

Hi I am new to azure and trying to run script job on my cluster; yesterday i was able to to do map reduce streaming job successfully; however today i am stuck when trying to do hive job ; on powershell ise when i type command use-azurehdinsightcluster 'nnn' I am getting specified method not supported
also when i try script file I get error start-azure job not supported...
I I have mysettings.publishsettings file imported and in place. I have azure.psd1
I am connected to azure etc...
one thing confuses me: account name there are three account names: xxxxx#hotmail.com; and one which is similar to my storage account name , and one weird pay-as-you-go
I have tried all of them
I am totally confused please can some one help me ?
Please upgrade to the latest powershell from http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/#Install and try again.