Is there a way to add errors from build step in TeamCity to the email notification? - email

I have a Powershell build step, and I'd like to add some messages fromt the script to the resulting email that is sent to people on the notification list. I see this happen for tests where the number of failures and the error is added to the email. But, how can I add my custom messages from the PowerShell build step to the resulting email?

Have you tried using service messages?
See here:http://confluence.jetbrains.com/display/TCD7/Build+Script+Interaction+with+TeamCity
You could use
write-host "##teamcity[message text='Its broken again' errorDetails='Your exception message' status='FAILURE']"

In order for the errors to be included in emails, I found I needed to add "compilationStarted" and "compilationFinished" tags, e.g:
##teamcity[compilationStarted compiler='Solution.sln']
##teamcity[message text='1>File.cpp(1): error C2065: "stackoverflow" : undeclared identifier' status='ERROR']
##teamcity[compilationFinished compiler='Solution.sln']
I use a Python script to parse the output from devenv, looking for specific strings to add as errors and warnings. The email adds these under a "compilation errors" section.

If you mean to pipe the output of an error that occurred in the Powershell script you are running then try piping the error object to a TeamCity service message after it has been caught
This is untested code but it might work for you:
trap [SystemException]
{
write-host "##teamcity[message text='An error occurred' errorDetails='$_' status='ERROR']";exit 1
}
OR
try
{
# Something...
}
catch
{
write-host "##teamcity[message text='An error occurred' errorDetails='$_' status='ERROR']";exit 1
}

Related

BTSKTask AddResource - How to raise an error in case the command fails

We are using the following command to deploy BizTalk assemblies via PowerShell:
BTSTask AddResource /ApplicationName:$App /Type:$BizTalkAssemblyType /Overwrite /Source:$Source /Options:GacOnAdd,GacOnInstall,GacOnImport
See: https://learn.microsoft.com/en-us/biztalk/core/addresource-command-biztalk-assembly
There are certain reasons this command can fail, e.g. an orchestration is not in the unenlisted state or one or more instances of the orchestration exists.
In this case the command does not raise an error so the script continues with an output like
Command failed with 1 errors, 0 warnings.
Because in this situation the assembly does not get deployed we would like to fail the PowerShell script e.g. by raising an error. How to achieve this?
You need to capture the output and check it for the failure, or rather, check for success and fail if it doesn't.
[array] $cmdOutput = BTSTask AddResource /ApplicationName:$App /Type:$BizTalkAssemblyType /Overwrite /Source:$Source /Options:"GacOnAdd,GacOnInstall,GacOnImport"
$line = $cmdOutput.Count-2
if ( $cmdOutput[$line] -eq "Command succeeded with 0 errors, 0 warnings.")
{
Write-Output "Deploy suceeded"
}
else
{
Throw "Deploy failed $cmdOutput"
}

Powershell - Try Catch - Non Powershell Errors

Is it possible to create a try-catch that catches a non-Powershell cmdlet error?
Example Error:
iperf3: error - unable to connect to server: Connection timed out
I want to catch that error and then try a different server for redundancy.
Thank you for the assist.
you can try to build your own powershell function and throw an error with "throw " but you have to identify the error on your own within the powershell function

FindItems() does not work in first run but works in the second run

I am trying to fetch latest mail from my Outlook Exchange server mailbox using PowerShell. I have seen that the most common solution is to do a FindItems() method on the inbox object. However, I find that that running the code first time throws error stating
Exception calling "FindItems" with "1" argument(s): "The request failed.
When I run it once again, the script completes successfully returning the last mail from my mailbox. In order to make it more clear, I wrote a script to execute the FindItems() method to execute twice in a while loop as shown below:
# bind to the Inbox folder of the target mailbox
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
echo outsideWhile
$i = 0
while ($i -ne 2) {
echo insideWhileBefore
$inbox.FindItems(1)
echo insideWhileAfter
$i += 1
}
The first execution of $inbox.FindItems(1) fails but the second execution goes through fine returning the desired results.
The result output is as shown below
outsideWhile
insideWhileBefore
Exception calling "FindItems" with "1" argument(s): "The request failed. The remote server returned an error: (501)" ........
insideWhileAfter
insideWhileBefore
<MAIL CONTENTS>
insideWhileAfter
Please help me out in understanding why this happening so and how I can overcome it.

How to get AWStats Error Notification via email?

I'm trying to find a way for an email notification in awstats.
The idea is that whenever there's an error (missing log files, statistics couldn't be generated) an email with an error message should be send to a specific email address.
I already found the config-Attribute "ErrorMessages" but as far as i get it its just for displaying an error.
Is there an attribute like "ErrorMessages" for activating mail notifications or do i have to implement it myself?
You can use cron job to run awstats update proccess.
And it'll sent update process result via email to you.
Example:
* * * * * /usr/local/awstats/update.sh | mail abc#xzy.com
I found a way to trap Errors while my code is executed. It's not an awstats feature, more a generic way:
Inside my script:
#Error Handling
set -e
function sendErrorNotification(){
echo "Awstats: An error occured during processing server logs." | mail -s "AWSTATS ERROR" "...#..."
}
trap sendErrorNotification EXIT
....code goes here...
set +e
trap - EXIT

I can't catch php exceptions using try....catch

I'm having a problem with PHP Exceptions. Even if I try to execute this code:
try {
$some->knownMethodWithError();
} catch(Zend_Exception $exp){
echo 'Error!: ' . $exp->getMessage();
}
My apache/php served web page always display a 500 Error. I mean,
echo 'Error!: ' . $exp->getMessage();
never is executed. I've tested with a redirection instead of that echo, but it doesn't work. Is there some php.ini directive that cause this behavior, or could it be something else?.
This happens in my Zend Framework based project.
Also, your code will only catch Zend_Exception.
If you have custom Exceptions maybe catch(Exception $e) will get more chances to catch all of them
maybe you could run the script with full logs. Change your php.ini on the server on the line :
error_reporting=E_ALL | E_STRICT
or better run it on an IDE environment with a debugger.
A 500 error isn't a PHP exception, it's happening above the code level. A 500 error means that there was an error while PHP was trying to parse your script (probably). Possibly your code has a syntax error.