sql-serverazure-devopsazure-pipelinesazure-pipelines-release-pipeline

Using Azure Devops deploy release to multiple repos


so I am trying to deploy changes from my CoreDb repo , that's a SQL database project to a release. This release would just be script changes that multiples countries would grab into their repos and make changes from there. I can't deploy directly to all the countries because some countries are on different versions than others.

The CoreDb repo is a SQL project as well that contains all the common files for all countries. I only handle the CoreDB repo, the country's local dev teams will handle their repos.

I created my CoreDB repo with a build pipeline and a release pipeline. I'm not sure how to connect the process of the country repos retrieving these releases (by version) for their own repos.

I was thinking either:

  1. create stages for every country in my CoreDb release pipeline that will manually be deployed, but then I'm not sure how we would handle merges in the sql files or will files get replaced? enter image description here

  2. Create a deployment task of some sort in my release pipeline that would execute scripts that would call the git commands to pull my CoreDb repo into their country's repo. The countries would update the script with their country name and what version they need and the script would do the git commands.

I already tried using git to pull the Core DB repo into my test project and merge the changes, which works, but my boss wants the process to be more streamlined, because we have 27 countries.


Solution

  • You can follow below steps to achieve:

    1.Prepare your source code in CoreDb repo. You can use the build pipeline to publish the artifact which contains the files.

    For example, i copied the target files and exclude .git folder below. You need to prepare the code base to your requirement.

    enter image description here

    1. Consume the build artifact in release pipeline:

    enter image description here

    1. In the release stage:

    a). git clone the 1st target repo.

    enter image description here

    You can get the target repo url following doc here. Add the Personal accesstoken in the url as above. And add pat as variables in 1st stage: enter image description here

    enter image description here

    b)With task copy files, replace the target files, tick overwrite option to use source files.

    enter image description here

    c) Push changes to target repo, and generate the changescript.

    enter image description here

    Script content below:

    cd targetrepo1
    git config --global user.email "tester1@example.com"
    git config --global user.name "tester1"
    
    # Check for changes before commit
    git status
    
    git add .
    git commit -m "Copy from source repo"
    git push origin main
    
    # Generate change script
    git diff --name-status HEAD~1 HEAD > changescript.txt
    
    # Display change script content
    echo "The file changes are below:"
    cat changescript.txt
    

    The files are copied to target repo and checked changescript content:

    enter image description here

    You can clone the stage and change the target repo, and pat ...etc in new stage, so that it can deploy to other target repo. enter image description here