You could use CopyFiles
task and git command to copy and push files in the repo. Check the sample below:
steps:
- checkout: self
persistCredentials: true
- task: CopyFiles@2
inputs:
SourceFolder: 'deployment'
Contents: '**'
TargetFolder: '$(Build.SourcesDirectory)/archival1'
- task: CopyFiles@2
inputs:
SourceFolder: 'deployment'
Contents: '**'
TargetFolder: '$(Build.SourcesDirectory)/archival2'
- script: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git checkout master
git add $(Build.SourcesDirectory)/archival1/** $(Build.SourcesDirectory)/archival2/**
git status
git commit -m "copy files"
git push origin master
If you want to delete the deployment
folder after copying the files, you could add the following to the pipeline:
- task: DeleteFiles@1
inputs:
SourceFolder: 'deployment'
Contents: '**'
RemoveSourceFolder: true
- script: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git checkout master
git add $(Build.SourcesDirectory)/deployment/**
git status
git commit -m "delete deployment folder"
git push origin master
Notice:
You need to grant version control permissions to the build service:
