0

​Hello,

I have created on bat file, that contains a lot of logic among them there is one command which I have to run to complete the whole logic of bat file. the command is robocopy with a timestamp.

MY Commands:

@echo off 
echo BUILD_SOURCESDIRECTORY contents: 
@dir %BUILD_SOURCESDIRECTORY% echo Over and out. 

@For /F "Tokens=1-5Delims=/: " %%G In (     '""%__AppDir__%Robocopy.exe" \: . /NJH 
/L|"%__AppDir__%find.exe" " 123""' )Do @Set "bdate=[%%I-%%H-%%G]-[%%J-%%K]" 

ROBOCOPY "%BUILD_SOURCESDIRECTORY%\Resources" "\\servername\Copy\%bdate%" /V

Note:

  • I know there is one task in Azure DevOps Server 2019 for robocopy "Windows Machine File Copy task" but I don't want to separate tasks.

  • I know there are so many arguments with robocopy that we can utilize but for checking purpose I have used only /V.

Error:​

2020-04-27T04:11:04.1190482Z ##[error]Process completed with exit code 1. 2020-04- 
27T04:11:04.1206512Z ##[debug]System.Exception: Process completed with exit code 1.    at 
Microsoft.VisualStudio.Services.Agent.Worker.Handlers.ProcessHandler.RunAsync()    at 
Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()    at 
Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken 
jobCancellationToken) 

But the strange is ----> folder is created with timestamp and files are also copied in the destination but still, the pipeline is getting failed.

Please let me know how we can overcome this error?

  • In your [previous question](https://stackoverflow.com/q/61119809), you reported exactly the same issue. That question was closed because it appeared to have been a duplicate of creating an independent date and time string. In my answer to you which did exactly that, you implied that you issue was not with that date and time string. I don't know if that was because you had not copied the code I provided without breaking its formatting, as you have in your question above, or whther it is still to do with the options you're using with [tag:robocopy]. Please provide your actual robocopy options! – Compo Apr 27 '20 at 12:14
  • In addition to my answers it is important that you understand the RoboCopy options and what they do. The `/V` option produces verbose output, which literally means that it outputs more words than strictly necessary. Those words include things such as the exit code, which in the example you've shown is `exit code 1`. Exit code 1 is attributed to one or more files were copied successfully, which is exactly what you've reported and to be expected. If you don't want to see the verbose output, redirect it to a file using a `/Log`|`/Log+`, `/UniLog`|`/UniLog+` option, or simply omit the `/V` option. – Compo Apr 28 '20 at 03:35

1 Answers1

0

This is more a solution to fix the very poor formatting of the code in your question.

You could have left it as one line, as I did in my previous answer to you.

@For /F "Tokens=1-5Delims=/: " %%G In ('""%__AppDir__%Robocopy.exe" \: . /NJH /L|"%__AppDir__%find.exe" " 123""')Do @Set "bdate=[%%I-%%H-%%G]-[%%J-%%K]"

If for easier reading/beautification purposes, you wanted to split the line over more lines, then the following two should do it:

@For /F "Tokens=1-5Delims=/: " %%G In ('%__AppDir__%Robocopy.exe \: . /NJH /L^
 ^|%__AppDir__%find.exe " 123"')Do @Set "bdate=[%%I-%%H-%%G]-[%%J-%%K]"

Although this three line split would be my preferred style:

@Echo BUILD_SOURCESDIRECTORY contents:
@Dir "%BUILD_SOURCESDIRECTORY%"
@Echo Over and out. 
@For /F "Tokens=1-5Delims=/: " %%G In (
    '""%__AppDir__%Robocopy.exe" \: . /NJH /L|"%__AppDir__%find.exe" " 123""'
)Do @Set "bdate=[%%I-%%H-%%G]-[%%J-%%K]"
@"%__AppDir__%Robocopy.exe" "%BUILD_SOURCESDIRECTORY%\Resources" "\\servername\Copy\%bdate%" /V

And please remember, that if you're not further using %bdate%, you don't need to define it as a variable, (as per my previous answer to you).

@For /F "Tokens=1-5Delims=/: " %%G In ('""%__AppDir__%Robocopy.exe" \: . /NJH /L|"%__AppDir__%find.exe" " 123""')Do @"%__AppDir__%Robocopy.exe" "%BUILD_SOURCESDIRECTORY%\Resources" "\\servername\Copy\[%%I-%%H-%%G]-[%%J-%%K]" /V
Compo
  • 30,301
  • 4
  • 20
  • 32
  • Hey @Compo! thanks for your suggestion regarding format. but I have also commented in my previous answer your logic didn't work... If you have seen I have changed my questions and your logic is still not working in my pipeline....please see above error which I have mentioned. – Dharti Sutariya Apr 28 '20 at 12:01
  • @DhartiSutariya, I have in my most recent comment, _(beneath your question)_, already explained that there is no error! What you are seeing is the verbose output, that you have specifically requested, _(by using the `/V` option with `RoboCopy`)_. What I can tell you is that there is absolutely nothing wrong with my logic, it appears that the only issue is your failure to read and understand the options for the command you are using. – Compo Apr 28 '20 at 12:08