I am trying to use a devops pipeline to copy a file within the same repository and branch from one folder to another.
I use the standard task for copying files and afterwards a powershell script to commit and deploy those changes to the branch.
I don't understand why I get this failure message when trying to push the changes to branch:
This is the code I am using for committing and push:
- task: PowerShell@2
displayName: PowerShell Script
inputs:
targetType: inline
script: >-
echo "commit all changes"
git config user.email "abi@presales.onmicrosoft.com "
git config user.name "ABI BI Build Service"
git add --all
git commit -m "Test Copy Files"
git push -u origin HEAD:dev
As shown in your screenshot, the current git credential is missing the password, which is the authentication information to access your repo.
To resolve this issue, you can try the suggestions below.
Prerequisites: Change settings and permissions in Azure DevOps
Add a checkout
task and set persistCredentials
to true
to leave the OAuth token in the Git config after the initial fetch.
steps:
- checkout: self
persistCredentials: true
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)/SourceFolder'
Contents: '{Your target files}'
TargetFolder: '$(Build.SourcesDirectory)/TargetFolder'
OverWrite: true
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
echo "commit all changes"
git config user.email "{Use email}"
git config user.name "{User name}"
git add --all
git commit -m "Test Copy Files"
git push -u origin HEAD:dev
Note: Ensure your current build is triggered from your dev
branch.
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
echo "commit all changes"
git config user.email "{Use email}"
git config user.name "{Use name}"
git add --all
git commit -m "Test Copy Files"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push -u origin HEAD:dev