0

I have a scheduled Jenkins Project to copy 30 files from one path to another overnight. In this project, i run a batch file stored in my desktop.

My use case is i do not want it to exit in case a file is not found. It is expected that sometimes only 25 out of 30 files will be found in the source folder. It should just carry on executing as normal. Now via Jenkins, I would like for it to send me the console log output of the build where the log should hold entries of the files not found.

The contents of the batch are as follows. (In the actual code I have 30, but only 2 files for this example.)

@echo off

rem The * at the end of the destination file is to avoid File/Directory Internal Question.

rem You can do this for each specific file. (Make sure you already have permissions to the path)
echo f | xcopy /f /s "C:\Orig\File1.txt" "C:\tgt\CopFile1.txt*"
echo f | xcopy /f /s "C:\Orig\File2.txt" "C:\tgt\CopFile2txt*"
exit

In my build step, I have selected "Execute Windows batch command", where i mention the path to the batch.

In case the whole build result is a "Failure", I have already enabled the send mail notification using the Extended-Email. Sometimes, 1 or 2 files are not found and as a result displays an "ERROR" in the console output, but the build shows as "Success".

Is it possible to get an email even when build is successful, but console log has "Error"?

Here is the "Default Content" of my Email notification:

<html>
<body>
You are receiving this email, because Build status identified as : <b>$BUILD_STATUS </b>
<br>
Build URL : $BUILD_URL
<br>
<br>
Console Output: -----------------------------------------------<br>
<pre>$BUILD_LOG</pre>
</body>
</html>
  • Almost certainly yes, but how to do that depends on how your job is set up -- there are dozens of different ways to tell Jenkins how to run a build; without more details about how your job is configured, we can't usefully tell you more than that. – tripleee Feb 11 '21 at 13:11
  • Updated the question with exact details: In my Build step, I have selected "Execute Windows batch command", where i mention the path to the batch. The batch has "xcopy \src \dir" – gaurav goswami Feb 12 '21 at 10:24
  • Not a stellar improvement, but I guess this is now clear enough to be marked as a duplicate of an existing question. The simplest fix is probably to force the batch script to exit with a failure when `xcopy` fails, either immediately or by way of setting a variable which sets the errorlevel at the end. – tripleee Feb 12 '21 at 10:38
  • Apparent duplicate of https://stackoverflow.com/questions/25121360/how-to-make-jenkins-fail-at-a-failing-windows-batch-command – tripleee Feb 12 '21 at 10:39
  • You can probably still get this question reopened if you [edit] it to clarify what exactly you have now and where you are stuck. Please review [How to ask](/help/how-to-ask) and the guidance for providing a [mre]. – tripleee Feb 16 '21 at 05:57
  • Thanks for the update, but it's still not clear how this is different from the proposed duplicate. Did you try putting in `|| exit /b whatever` or `|| goto :error` after each `xcopy` command, for example? – tripleee Feb 16 '21 at 06:46
  • My use case is i do not want it to exit in case a file is not found. It is expected that sometimes only 25 out of 30 files will be found in the source folder. It should just carry on executing as normal. Now via Jenkins, it should send me the console log output of the build where the log should hold etries of the files not found. – gaurav goswami Feb 16 '21 at 07:52

0 Answers0