Does azure pipeline 'command line' agent job inherit working directory from the previous job?

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

No, the Azure Pipeline "Command Line" agent job does not inherit the working directory from the previous job by default. Each job in an Azure Pipeline runs in an isolated environment with its own working directory.

The working directory for each job is typically set explicitly within the job configuration using the workingDirectory parameter. By default, if the workingDirectory is not specified, the job will use the default working directory, which is the root directory of the repository associated with the pipeline.

If you want to share or pass the working directory from one job to another, you can use predefined or custom variables in Azure Pipelines. You can set a variable in one job and then use it in subsequent jobs by referencing it using the syntax $(variableName).

For example, you can set a variable in one job like this:

yaml
- job: SetWorkingDir
steps:
- script: echo "##vso[task.setvariable variable=MyWorkingDir]$(System.DefaultWorkingDirectory)"

Then, in the subsequent job, you can reference the variable as the working directory:

yaml
- job: UseWorkingDir
steps:
- script: |
cd $(MyWorkingDir)
# Perform actions in the specified working directory

This way, you can pass the working directory from one job to another within your Azure Pipeline.