microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.42k stars 2.59k forks source link

BatchScript not respecting workingFolder when multiple repos are checked out #14271

Closed milbrandt closed 3 years ago

milbrandt commented 3 years ago

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Bug

Enter Task Name: BatchScript@1

Environment

Issue Description

When two repos are checked out, the working directory is not taken to execute the script. Instead it is searched in directory s.

- task: BatchScript@1
  inputs:
    workingFolder: '$(SrcDir)'
    filename: 'builds\setupdevenv.cmd'
    arguments: instpkg 3rdpty man

When only one repo is checked out (in directory src, the script is running.

Workaround: using script task

- script: builds\setupdevenv.cmd instpkg 3rdpty man
  workingDirectory: $(SrcDir)

Task logs

logs_87193.zip

Error logs

`2021-01-22T20:39:58.7047072Z ##[debug]Working directory: 'D:_2\46\src\' 2021-01-22T20:39:58.7048548Z ##[debug]Fail on standard error: 'True' 2021-01-22T20:39:58.7049408Z ##[debug]Modify environment: 'False' 2021-01-22T20:39:58.7049862Z ##[debug]C:\Windows\system32\cmd.exe /c "D:_2\46\s\builds\setupdevenv.cmd instpkg 3rdpty" 2021-01-22T20:39:58.7051039Z ##[command]D:_2\46\s\builds\setupdevenv.cmd instpkg 3rdpty 2021-01-22T20:39:58.7101778Z ##[error]The system cannot find the path specified.

2021-01-22T20:39:58.7247451Z ##[error]Process completed with exit code 1 and had 1 error(s) written to the error stream. 2021-01-22T20:39:58.7250783Z ##[debug]System.Exception: Process completed with exit code 1 and had 1 error(s) written to the error stream. 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) 2021-01-22T20:39:58.7253475Z ##[section]Finishing: Setup`

DaniilShmelev commented 3 years ago

Hi @milbrandt! The task is working as expected; the workingFolder input is only used to specify the working directory that your batch script will use. It doesn't affect the path to the script. So the fix would be to use:

- task: BatchScript@1
  inputs:
    workingFolder: '$(SrcDir)'
    filename: '$(SrcDir)\builds\setupdevenv.cmd'
    arguments: instpkg 3rdpty man

By the way, the workaround with script works because in the context of $(SrcDir) the path builds\setupdevenv.cmd is indeed valid, so both tasks work as expected.

DaniilShmelev commented 3 years ago

Could you please confirm if the issue is resolved with this fix?

milbrandt commented 3 years ago

@DaniilShmelev Your solution works. But then the documentation should be more prcise:

filenamePath (Required) Path of the cmd or bat script to execute. Should be fully qualified path or relative to the default working directory

The filenamePath in my report was relative to working folder. For me as a non-native English speaker It was not obvious that there is a difference between working folder and working directory.

And different behaviour of the two similar tasks (cross platform script and BashScript) is surprising at least for me.