I am converting a Classic Azure build pipeline into a YAML pipeline and I have this step defined:
parameters:
RestoreBuildProjects: '**/*.csproj'
buildConfiguration: 'Any CPU'
TestProjects: '**/*Tests/*.csproj'
stages:
- stage: Build
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
jobs:
- job: Build_Application
continueOnError: false
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: true
- script: |
npm install --no-fund -g git+https://builduser:$(System.AccessToken)@ourrepos.visualstudio.com/Projects/_git/Util
displayName: 'npm install util'
workingDirectory: $(Build.SourcesDirectory)
This fails with the following error:
npm ERR! command git --no-replace-objects ls-remote https://builduser:***@ourrepos.visualstudio.com/Projects/_git/Util
npm ERR! remote: TF401019: The Git repository with name or identifier Util does not exist or you do not have permissions for the operation you are attempting.
npm ERR! fatal: repository 'https://ourrepos.visualstudio.com/Projects/_git/Util/' not found
I have tried:
- With and without the
checkout
step - With and without
sudo npm
- Switching
builduser
foruser
- Passing the
System.AccessToken
in from the parent YAML file as a parameter - Ensured
Limit job authorization scope to current project for non-release pipelines
is OFF - Ensured
Limit job authorization scope to current project for release pipelines
is OFF - Ensured
Protect access to repositories in YAML pipelines
is OFF
And variations of these.
The script step in question does, of course, work in the Classic pipeline, but not in the YAML pipeline and I can’t help but think I am missing some detail of running scripts or accessing environment variables specific to YAML.
Is there anything else I might need to do?
2
Answers
As you could run your pipeline in the classic pipeline, you may check the Build job authorization scope in your classic pipeline.
If it is Current project, you may enable Limit job authorization scope to current project for non-release pipelines
And check the Service Account: {Project Name} Build Service ({Org Name}) has the Read Permission in your target repo(Util): Project Settings -> Repositories -> Target repos(Util) -> Security.
If Build job authorization scope is Project Collection.
You may disable the Limit job authorization scope to current project for non-release pipelines for your project ourrepos.visualstudio.com/Projects/
and check the Service Account: Project Collection Build Service (OrganizationName) has the Read Permission in your target repo(Util):
Project Settings -> Repositories -> Target repos(Util) -> Security.
Since Util repo is in the same organization but in different project, as per the error message, please follow below items for a check. I tested your yaml and it’s working on my side:
correct git url
when youclone repository
:The
npm install command
should be like below:npm install --no-fund -g git+https://builduser:$(System.AccessToken)@{orgname}.visualstudio.com/{projectname}/_git/{reponame}
your project which have your YAML pipeline
, make sure:Limit job authorization scope to current project for non-release pipelines
isOFF
.Protect access to repositories in YAML pipelines
isOFF
.SOURCE repository
, Make sureProject Collection Build Service Accounts
hasread
permission.My pipeline result: