I am trying to use an Azure DevOps CI Pipeline to validate code of other repositories while the pull request.
Regarding to this, I have created a central repository with a .yml
-file for linting the powershell code of another repository.
As this will be a Branch Policy
> Build Validation
-task, I need to checkout the central repository and the repository which I would like to check.
Multiple hardcoded repository checkout isn't that problem. So far, so good.
The problem is, to make the to be checked repository checkout dynamic :(
What am I trying to do?
I am trying to get the REPOSITORYNAME
with RegEx in Powershell, set it as a variable and trying to checkout repository dynamically:
System.PullRequest.SourceRepositoryURI = https://XXX@dev.azure.com/YYY/ZZZ/_git/REPOSITORYNAME
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
steps:
- powershell: |
$regex = [regex]::Match($env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI, "/([^/]+)$")
$repositoryName = $regex.Groups[1].Value
Write-Host $repositoryName
Write-Host "##vso[task.setvariable variable=repositoryName;]$repositoryName"
Write-Host "Variable 'repositoryName' has been set."
displayName: 'Set variable(s) with PowerShell'
- checkout: self
- checkout: git://$(SYSTEM.TEAMPROJECT)/$(repositoryName)@$(SYSTEM.PULLREQUEST.TARGETBRANCHNAME) # Azure Repos Git repository in the same organization
As well, I tried to use another method of checkout, Condition
and if
-statement without success.
I am wondering why the $(repositoryName)
isn't working as expected?
Any suggestions?