Replace Build.SourcesDirectory with System.DefaultWorkingDirectory#16032
Replace Build.SourcesDirectory with System.DefaultWorkingDirectory#16032MiYanni merged 3 commits intodotnet:mainfrom
Conversation
|
I've manually changed these files on a branch in the repo I'm testing. These changes seem to break signing, but I'm not sure how.
You'll see the working directory is |
were you doing full signing? The signing binlog might help. This seems to be coming from the sign tool. |
The signing binlog didn't provide any information. Basically only said "starting signing". I think that's because it couldn't find the actual sign tool or something like that. As mentioned, installing it (MicroBuild) in the default location worked. |
|
I am noticing something that is not correct when using |
…y, except for installing MicroBuild.
| # NOTE: There's something that relies on this being in the "default" source directory for tasks such as Signing to work properly. | ||
| microBuildOutputFolder: '$(Build.SourcesDirectory)' |
There was a problem hiding this comment.
This is a bug with how MicroBuild is handling the output folder. Someone should investigate this as changing the value here breaks Signing. As long as the MicroBuild tools are installed into Build.SourcesDirectory, everything seems to work properly, so this cannot be changed currently.
|
|
||
| Optional variables: | ||
| EnableDefaultArtifacts Includes *.nupkg, *.vsix and *.wixpack.zip under "/artifacts/packages/**" for sigining. | ||
| EnableDefaultArtifacts Includes *.nupkg, *.vsix and *.wixpack.zip under "/artifacts/packages/**" for signing. |
joeloff
left a comment
There was a problem hiding this comment.
Makes sense, especially for the use cases in the SDK side where we plan to have multiple repos. But definitely suggest someone from dnceng to take a look in case this can impact other repos that consume Arcade
|
Also note, I'll need to make similar PRs for Arcade 8 and 9. |
|
Added @ellahathaway for the aforementioned MicroBuild install problem as I looked through the history and saw it was changed from |
The install problem you’re seeing is #15731. @dotnet/dnceng |
chcosta
left a comment
There was a problem hiding this comment.
I don't have a strong opinion here. According to the documentation I dug through, the behavioral differences here are super nuanced, and despite the claim, that build.sourcesdirectory and system.defaultworkingdirectory are different, they're not supposed to be. so I don't have a clear recommend. it seems safe either way and I'd defer to someone who has actually spent time exploring those nuances.
The behavior I'd expect is
steps:
- checkout: git://project/first
path: repo/first-repo
- checkout: git://project/second
path: repo/second-repo
workspaceRepo: true
- script: |
echo "Current directory: $(pwd)"
# Output: $(Pipeline.Workspace)/repo/second-repo
echo "Build.SourcesDirectory: $(Build.SourcesDirectory)"
# Output: $(Pipeline.Workspace)/s (NOT the working directory!)
echo "System.DefaultWorkingDirectory: $(System.DefaultWorkingDirectory)"
# Output: $(Pipeline.Workspace)/s (NOT the working directory!)
Summary
Currently,
Build.SourcesDirectoryis used to access the directory for which the code is checked out. However, this predefined variable does not work for multi-repo checkout situations. The proper variable that works for both single-checkout and multi-checkout pipelines isSystem.DefaultWorkingDirectory. There is alsoBuild.Repository.LocalPath, but that does not have the desired outcome. More explanation in the Details section.There is an additional change adding
repositoryAliastojobs.yml. This allows you to pass in the repository you want to runpublish-build-assets.ymlfrom. Otherwise, the default ofselfmay not have Arcade. This commit encompasses those changes. Not sure if there is a doc that needs to be updated or not. Based on the docs,repositoryAliasseems to be an appropriate name.Docs
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables-devops-services
Build.SourcesDirectory
Build.Repository.LocalPath
System.DefaultWorkingDirectory
Details
I found this when trying to do a multi-checkout pipeline that uses Arcade within the primary repo. The SBOM generation task would fail because it couldn't locate the artifacts folder. Therefore, I figured that I should apply this change to all files in the repo to make them work properly with multi-checkout pipelines.
At first, I tested
Build.Repository.LocalPath, but there is a reason this is not the correct value to use. See the Example below.Example
My pipeline,
example.yml, is in a repository namedRepoA. This pipeline pulls in a different repo,RepoB. In the yml, it would look like this:RepoA/example.ymlSo, you have
RepoAthat referencesRepoB. So, when you go to docheckout(which needs to be provided in the yml because of multiple repos), it might look something like this:RepoA/example.ymlThe main thing to notice is that
RepoBhasworkspaceRepo: trueon it. What does that do? It sets the working directory for Azure Pipelines to RepoB's directory. So, here are what the paths look like for reference:D:\a\_work\1\s(what a single repo checkout uses)D:\a\_work\1\RepoA(based on settingpathon checkout)D:\a\_work\1\RepoB(based on settingpathon checkout)With this knowledge, how does that affect the predefined variables? Here is what you end up with (by spitting out the env vars that represent the predefined variables):
Since you've set the working directory using the
workspaceRepovalue, the intended directory is the one defined inSystem.DefaultWorkingDirectory. Therefore, this is the correct variable to use. Note that all 3 of these variables are set toD:\a\_work\1\sin a single-repo checkout scenario (the typical scenario).