Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to use a checkout path of any repository as the default working directory (System.DefaultWorkingDirectory) #3479

Merged

Conversation

echalone
Copy link
Contributor

@echalone echalone commented Aug 3, 2021

Synopsis

Added boolean option (using predefined option workspaceRepo) to checkout task to define the path of a checked out repository as the default working directory. The source path of the first checkout build step in a Yaml Pipeline that uses and sets the "workspaceRepo" option to true will become the path for the System.DefaultWorkingDirectory (instead of setting it to the the same value as the Build.SourcesDirectory). Also adapted the BuildJobExtension to use the value of the System.DefaultWorkingDirectory build variable, instead of the Build.SourcesDirectory build variable, for the "working directory" and resolve file paths to the path of the System.DefaultWorkingDirectory build variable. This is backwards compatible since if the pipeline is not using this new option then System.DefaultWorkingDirectory will just point to the same location as Build.SourcesDirectory does.

Scripts and executable files as well as file inputs to tasks will now resolve to the System.DefaultWorkingDirectory, which can now be adapted to be set to the checkout path of a desired repository if the default behaviour of it pointing to "\s" is not desired (important for pipelines checking out to a different location than the default path).

The feature request for this new option can be found here: #3484

Also added UnitTests for this new setting.

New boolean option

For now I've used the currently unused and undocumented checkout task option "workspaceRepo" as defined as field WorkspaceRepo in the Microsoft.TeamFoundation.DistributedTask.Pipelines.PipelineConstants.CheckoutTaskInputs class. If another (and differntly named) new field should be used this will need to be defined in the Microsoft.TeamFoundation.DistributedTask.Pipelines.PipelineConstants.CheckoutTaskInputs class first by Microsoft (it's not public code, I can't help there).

Important: No matter if this existing field is used or a new one, currently there exists NO such option in the Yaml pipeline checkout task syntax and after this new functionality has been added to the build agent (by accepting the pull request) Microsoft still needs to add the new option to the Yaml pipeline checkout task syntax (and its documentation) so it can actually be used in the checkout build step of Yaml pipelines! This, again, is not public code, so I can't help there.

…h of a checked out repository as the default working directory.

Also added UnitTests for this new setting.
@DenisRumyantsev DenisRumyantsev requested review from a team as code owners January 26, 2023 14:39
@DenisRumyantsev
Copy link
Contributor

Hi, @echalone, thanks for your contribution.
Could you test your changes end-to-end to verify they work as expected for you?

Steps to test these changes:

  1. Build the agent and configure it as self-hosted.
  2. Create and run a test pipeline that contains checkout steps —
pool: <Self-Hosted Agent Pool>

resources:
  repositories:
  - repository: first
    type: github
    endpoint: <github-endpoint>
    name: <github-username>/<first-repo>
  - repository: second
    type: github
    endpoint: <github-endpoint>
    name: <github-username>/<second-repo>

steps:
- task: Checkout@1
  inputs:
    repository: first
    path: first/repo/custom/path
    workspaceRepo: false
  displayName: Checkout First Repo

- task: Checkout@1
  inputs:
    repository: second
    path: second/repo/custom/path
    workspaceRepo: true
  displayName: Checkout Second Repo

- bash: |
    echo ">>> Current working directory:"
    pwd
    echo ">>> Items in this directory:"
    ls
  displayName: Check Result

@DenisRumyantsev
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@DenisRumyantsev DenisRumyantsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @echalone, I tested this PR. The workspaceRepo option works properly, thanks.

@echalone
Copy link
Contributor Author

echalone commented Mar 9, 2023

Hi, @echalone, I tested this PR. The workspaceRepo option works properly, thanks.

thanks @DenisRumyantsev and you're welcome :) what's the next step? An approval by the microsoft/azure-pipelines-platform group?

@DenisRumyantsev
Copy link
Contributor

DenisRumyantsev commented Jun 5, 2024

/azp run

@microsoft microsoft deleted a comment from azure-pipelines bot Jun 5, 2024
@microsoft microsoft deleted a comment from azure-pipelines bot Jun 5, 2024
@DenisRumyantsev DenisRumyantsev force-pushed the users/echalone/DefaultWorkspaceRepo branch from 5453cda to f1c294b Compare June 5, 2024 09:59
@microsoft microsoft deleted a comment from azure-pipelines bot Jun 5, 2024
@microsoft microsoft deleted a comment from azure-pipelines bot Jun 5, 2024
@microsoft microsoft deleted a comment from azure-pipelines bot Jun 11, 2024
@DenisRumyantsev DenisRumyantsev merged commit 7ac6ef3 into microsoft:master Jun 11, 2024
12 checks passed
@echalone
Copy link
Contributor Author

awesome, thanks so much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants