1

Here is my scenario:

I have a scenario where after a successful git push to a deployment folder (SSIS and TSQL scripts) in azure repos, I have to move the files in deployment folder to multiple archival folders inside the repos(SSIS and TSQL) after successful build. I need to achieve this with azure devops build and release process. any help is really appreciated.

gdw
  • 23
  • 1
  • 3
  • This is an X-Y problem. You don't need to move scripts around in source control after deployment, you need to ensure that the scripts are idempotent so that it's safe to run them multiple times. – Daniel Mann Feb 22 '21 at 23:21

1 Answers1

1

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:

enter image description here

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39