63

I'm developing a CI for Python package in Azure Pipelines (https://github.com/scikit-image/scikit-image/blob/azure-pipelines/azure-pipelines.yml). At some point, I need to step out of the source code directory to allow pytest to discover an installation of this package, and run the corresponding tests.

The issue I'm facing is related to the fact that cd, cd C:, etc commands do not seem to cause any effect, so that the current working directory remains unchanged (in this specific case, D:\a\1\s).

Is there a way to overcome the described limitation?

soupault
  • 6,089
  • 4
  • 24
  • 35

2 Answers2

132

It took many hours to find the solution, but, apparently, there is a way to specify working directory for specific script - https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/command-line?view=vsts&tabs=yaml :

- script: # script path or inline
  workingDirectory: #
  displayName: #
  failOnStderr: #
  env:  # mapping of environment variables to add
soupault
  • 6,089
  • 4
  • 24
  • 35
  • 2
    Do you also know how to put it to the folder of the pipeline (which seems a common use case)? – Roelant Feb 03 '20 at 08:39
  • 4
    What do you mean exactly? You can just use `workingDirectory: subfolder/` at each step inside your YAML where subfolder is relative to repository root. You need this even if your pipeline is located at `subfolder/azure-pipeline.yml` – julie-ng Mar 25 '20 at 09:55
  • 4
    The answer just highlights that there is a `workingDirectory:` modifier. At the time of posting this info was really hard to find. – soupault Mar 25 '20 at 13:11
19

Simple Solution to know the directory location in Azure devops :-

- task: CmdLine@2
  inputs:
    script: |
      echo  '$(System.DefaultWorkingDirectory)'
      dir
      dir subfoldername

where you need to invoke the command line and get the current path by using System.DefaultWorkingDirectory and dir will list you all the folders and files and using dir subfoldername we can traverse into subfolders

Shivam Tyagi
  • 306
  • 3
  • 3