Usage Information
latest
Description
I have two repositories in Azure DevOps pipeline: infra and app.
The Azure DevOps pipeline is defined in the infra repository, while the application source code is in the app repository. I trigger the pipeline manually.
[GitRepository]
readonly GitRepository GitRepository;
When I access following prop value that return incorrect value means it's return infra repo values instead of app repo values.
GitRepository.Commit
GitRepository.Branch
However GitRepository.HttpsUrl or GitRepository.Head is return correct values
Reproduction Steps
NukeBuild code:
class Build : NukeBuild
{
[GitRepository]
readonly GitRepository GitRepository;
Target Print => _ => _
.Executes(() =>
{
Log.Information("NukeBuild RootDirectory = {Value}", NukeBuild.RootDirectory);
Log.Information("Commit = {Value}", GitRepository.Commit);
Log.Information("Branch = {Value}", GitRepository.Branch);
Log.Information("Https URL = {Value}", GitRepository.HttpsUrl);
Log.Information("SSH URL = {Value}", GitRepository.SshUrl);
Log.Information("LocalDirectory = {Value}", GitRepository.LocalDirectory);
Log.Information("Head = {Value}", GitRepository.Head);
});
}
Azure DevOps pipeline at infra repo:
declare repo:
resources:
repositories:
- repository: app
type: git
name: {Project }/{Repo}
I checkout app repo specific path in azure devops pipeline
e.g.
- checkout: app
displayName: 'Checkout source code'
path: repo/app
fetchDepth: '1'
submodules: 'false'
last run build.cmd with required param
- script: |
build.cmd BuildArtifacts --configuration $(buildConfiguration) --version $(Build.BuildNumber) --RootDirectory "$(appRootDirectory)"
displayName: 'Build Solution using Nuke Build'
workingDirectory: '$(appRootDirectory)'
Note: I already provided --RootDirectory "$(appRootDirectory)" param so when GitRepository instance created then it will use this directory.
Expected Behavior
GitRepository.Commit and GitRepository.Branch values return correct values from app repo instead of infra repo
Actual Behavior
Only the GitRepository.Commit and GitRepository.Branch values are incorrect. Other properties, such as GitRepository.HttpsUrl and GitRepository.Head, are returning the correct values.
Regression?
I found the cause AzurePipelines : Host, IBuildServer use azure devops env. values which contains value of infra repo.
|
string IBuildServer.Branch => SourceBranch; |
|
string IBuildServer.Commit => SourceVersion; |
|
public string SourceBranch => EnvironmentInfo.GetVariable("BUILD_SOURCEBRANCH"); |
But if the GitRepository instance is created from a local directory, it should use the local folder branch and last commit values instead of the azure devops pipeline repo values.
|
public class GitRepositoryAttribute : ValueInjectionAttributeBase |
|
{ |
|
public override object GetValue(MemberInfo member, object instance) |
|
{ |
|
return GitRepository.FromLocalDirectory(Build.RootDirectory); |
|
} |
|
} |
Known Workarounds
No response
Could you help with a pull-request?
No
Usage Information
latest
Description
I have two repositories in Azure DevOps pipeline:
infraandapp.The Azure DevOps pipeline is defined in the
infrarepository, while the application source code is in theapprepository. I trigger the pipeline manually.When I access following prop value that return incorrect value means it's return
infrarepo values instead ofapprepo values.However
GitRepository.HttpsUrlorGitRepository.Headis return correct valuesReproduction Steps
NukeBuild code:
Azure DevOps pipeline at
infrarepo:declare repo:
I checkout
apprepo specific path in azure devops pipelinee.g.
last run build.cmd with required param
Note: I already provided
--RootDirectory "$(appRootDirectory)"param so when GitRepository instance created then it will use this directory.Expected Behavior
GitRepository.CommitandGitRepository.Branchvalues return correct values fromapprepo instead ofinfrarepoActual Behavior
Only the
GitRepository.CommitandGitRepository.Branchvalues are incorrect. Other properties, such asGitRepository.HttpsUrlandGitRepository.Head, are returning the correct values.Regression?
I found the cause
AzurePipelines : Host, IBuildServeruse azure devops env. values which contains value ofinfrarepo.nuke/source/Nuke.Common/CI/AzurePipelines/AzurePipelines.cs
Lines 40 to 41 in 27e8077
nuke/source/Nuke.Common/CI/AzurePipelines/AzurePipelines.cs
Line 72 in 27e8077
But if the
GitRepositoryinstance is created from a local directory, it should use the local folder branch and last commit values instead of the azure devops pipeline repo values.nuke/source/Nuke.Common/Attributes/GitRepositoryAttribute.cs
Lines 18 to 24 in 27e8077
Known Workarounds
No response
Could you help with a pull-request?
No