2015-12-26 46 views
0

我已经写批处理文件70天后我们将在下面如何处理在批处理文件删除cmd在文件的情况下删除

forfiles /p "%SourceFolderLocation%" /s /m *.zip /c "cmd /c Del @path" /d -%NumberOfDaysForFolderToExists%

我使用删除扩展名为.zip文件不存在这个批处理文件在Jenkis Job中。每当删除批处理文件没有得到比指定日期早的指定文件时,jenkins作业失败。

我们有什么方法可以阻止jenkins作业失败,如果该文件还没有被发现删除?

由于提前....

+0

作业的控制台输出中显示的错误是什么?在你的问题中,你声明,当“删除批处理文件没有得到......然后Jenkins作业失败”。但是,如果没有找到文件,是否有任何方法可以使工作失败......看起来您正在询问已经展示的行为。如果没有要删除的文件,您是否希望詹金斯的工作能够成功? –

+0

@ JohnBartels-是的,在两种情况下都应该通过这项工作。 – picnic4u

回答

1

ForFiles Return values

If ForFiles finds one or more matches if will return Errorlevel =0
If ForFiles finds no matches if will return Errorlevel =1 and will print "ERROR: No files found with the specified search criteria."

整个脚本可能如下(如果forfiles唯一原因詹金斯工作失败):

rem … (previous commands here) 
2>NUL forfiles /p "%SourceFolderLocation%" /s /m *.zip /c "cmd /c Del @path" /d -%NumberOfDaysForFolderToExists% 
(call) 
rem … (next commands here) 
exit /B 0 

对于(call)招说明,请参阅戴夫贝纳姆的答复setting ERRORLEVEL to 0问题:

If you want to force the errorlevel to 0, then you can use this totally non-intuitive, but very effective syntax: (call) . The space after call is critical. If you want to set the errorlevel to 1, you can use (call) . It is critical that there not be any space after call.