0
votes

Need some inputs on how can we trigger release pipeline to copy the respective .json file to Azure storage account based on the commit done to specific folder in master branch.

Currently, when there is change in API1- .json file, all the .json will be copied to the storage account which is done via Azure Copy File task.

master
--- Applications
  --- API1(folder1)
         sample.json
  --- API2(folder2)
         sample.json
   --- API3(folder3)
         sample.json

NOTE: Above is not a git repo, its a normal repo to store API files, Im not using build pipeline to get the artifacts, in release pipeline im referring to the the Azure git repo directly.

How can I only copy the API1 .json file if there is commit to the respective folder(API1) and copy to specific storage account?

Can we achieve this using single Azure copy task or should we have multiple Azure copy task created?

1

1 Answers

0
votes

How can I only copy the API1 .json file if there is commit to the respective folder(API1) and copy to specific storage account?

We can do this via single Azure copy task, we can enter the file path in the field Source and select storage account via the field RM Storage Account.

there is commit to the respective folder(API1)

If the release pipeline artifact is build, we can check the build commit info via this API to get the latest commit ID(Note: the commit id is sourceVersion in the response body), then we can get the commit Folder path via commit ID

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=6.0-preview.1

We can determine the file path and save the result in the new variable(Such as A1), then add condition eq(variables['A1'], 'true') in the task Azure copy to run it.

If you run build after multiple commits, you need get the latest build number and before build number, then get these commit ID. And get the commit date via the commit ID, then use the rest API to list all the commits between builds. And check the commit path via the code for. You can refer the this answer for more details.