Reputation: 109
we have an application that relies on multiple independent code modules - they do no interact with each-other. See below a rough example:
........
Considering the code is all for one application but each module is independent of each other, how do i set up the repository for it so that it accomplishes the following:
The only solution I see is creating a repo for each module, but I am hoping someone knows of a more elegant methodology than that.
Note: I am not a full time developer - I qualify more for Operations Management and my knowledge of Git/repos/etc is limited - so I admit i might be missing a glaring piece of information that would make this question moot.
Upvotes: 0
Views: 189
Reputation: 30383
If you have many modules and donot want to create pipeline for each module, you can consider below workaround.
If the module1 is in folder module1 of your repo. You can run git command git diff --name-only HEAD HEAD~1
in a script task to get the which module get updated. And set module folder to a variable using statement ##vso[task.setvariable]
. Then you can configure the Build task to build the changed module only. Please check out below example:
Check document to learn more about task.setvariable. Check here to learn more about Conditions.
steps:
- powershell: |
#get the changed files
$a = git diff --name-only HEAD HEAD~1
#get the changed module folders
$folders = $a | foreach {$_.split("/")[0]}
#assign the folders to variable folderName
echo "##vso[task.setvariable variable=folderName]$folders"
#this build task will only be executed when module1 changed
- task: VSBuild@1
displayName: Build Module1
condition: contains(variables.folderName, 'module1')
#this build task will only be executed when module2 changed
- task: VSBuild@1
displayName: Build Module2
condition: contains(variables.fileName, 'module2')
Above yaml is a simple example. You might need to change the powershell task scripts a little bit according to your project. You can use only one build task, if all the modules use the same build configuration.
Upvotes: 1
Reputation: 40939
To achieve your goals you should consider these steps:
specific path build
trigger:
branches:
include:
- master
- releases/*
paths:
include:
- Module-1/*
exclude:
- '*'
Above configuration setup a CI trigger only for Module-1 ignoring changes in other directories. Later in that script you can preapre package and deployment only for Module-1
if you decide for step above, you should also consider using templates to avoid repeating yourself. Please check the documentation.
you should also [add branch policy] to block direct commits to master branch. Here you can also consider approval from additional service to check if you have in PR changes done in few modules. In this case you can decide fail that PR. For more info please check this two links:
Above steps should give you selective builds and deployments and fails PR when changes spread across many modules. I know that this is far away from a working solution, but I hope that at least I show you direction which you should follow.
Upvotes: 1