I have an azure devops pipeline that checks out two repositories with the following command
resources:
repositories:
- repository: 'essentials'
type : 'git'
name : 'ic-essentials'
steps:
- checkout: self
persistCredentials: true
- checkout: 'essentials'
note essentials
is a different repository to self
.
later on it creates a file in the essentials
repository with the following templated pipeline,
parameters:
- name: SolutionName
type: string
displayName: 'Name of the Solution to be saved'
- name: Version
type: string
displayName: 'Semver version of the solution'
- name: CoreRepository
type: string
displayName: 'Name of the core repository'
steps:
- task: PowerShell@2
displayName: 'Setting git default'
inputs:
targetType: 'inline'
script: |
git config --global user.email $(Git.UserEmail)
git config --global user.name $(Git.UserName)
- task: PowerShell@2
displayName: 'Create manifest'
inputs:
targetType: 'inline'
script: |
Write-Host "Logic for manifest creation is loaded"
# A logic that creates a file in the following location
# $(Build.SourcesDirectory)/${{parameters.CoreRepository}}/Manifest
- task: PowerShell@2
displayName: 'Committing files and pushing'
inputs:
targetType: 'inline'
script: |
Set-Location -Path $(Build.SourcesDirectory)/${{parameters.CoreRepository}}
git push --set-upstream origin main
git add .
git commit -m "Committing the manifest file"
git push origin HEAD:main
i am getting the following error,
error: src refspec main does not match any
error: failed to push some refs to 'https://dev.azure.com/MyOrg/MyProj/_git/MyRepo'
[detached HEAD f327404] Committing the manifest file
1 file changed, 8 insertions(+)
create mode 100644 Manifest/THEFILE.manifest.xml
fatal: could not read Password for 'https://[email protected]': terminal prompts disabled
##[error]PowerShell exited with code '1'.
i can confirm
- the repository exists. Also does the branch
main
- the file is definitely getting created in the stipulated location.
- the agent
My Project Build Service (My Org)
as contributor access to the repository.
I still think its to do with the access the agent has to the repository. am I overlooking something obvious?
2
Answers
You can use a small script to handle the credentials:
Based on this document, you may test the sample below.
Hope this helps.