I have a below script to do the job to scan the latest folder which should contain the wanted file from build.
Since it is a runtime, now the issue is sometimes the last (latest) folder created but somehow the wanted file not generated yet or this build (folder) only for something else....
So how can we modify this script to find the last second one which will contain the file desired if the last folder not having the file yet.
Since the build number folder is not known in this case. So my first option is to get the latest build number folder as below.
However, there are two exceptions. First this build (folder) may not have desired file, or second the build has this file but is running to generating and not ready yet....
Code: Select all
@echo off
set agentsource=C:\bamboo-agent-home\build-dir\BA-CAEXTEST-RAT\source
set remotesource=\\ussnprdevapp8\bamboo2_artifacts
set plannum=plan-430113518
set flavr=CHC
::scan the latest folder
FOR /F "delims=" %%i IN ('dir "%remotesource%\%plannum%\shared" /b /ad-h /t:c /od') DO SET newfld=%%i
echo Most recent subfolder: %newfld%
::prepare the latest package
if not exist %agentsource% (md %agentsource%)
if exist %agentsource%\*.zip (del %agentsource%\*.zip)
copy "%remotesource%\%plannum%\shared\%newfld%\A591\*_%flavr%_*.zip" "%agentsource%"
echo %ERRORLEVEL%