Continuous integration (CI) is the process in which the build/evolve/deploy process is automated using tools.
One aspect of Continuous integration is the ability to apply additional data changes that may be needed for a complete deploy, and, to handle this need in a CI environment, we have the Documentation:ScriptAfterEvolve functionality of MDrivenServer.
But what is also needed is to do the following steps via automation/script:
- Generate all code - to ensure the code maps 100% to the model
- Rebuild all - to ensure that assemblies are correctly built prior to upload for use with CodeDress
- Upload to MDrivenServer - to initiate the evolve of the database
A few new features have been added to the MDrivenFramework extension of VS2022 to facilitate these steps.
An example script can be found in our GitHub repository: supportMDriven\MDrivenComponents\MDrivenTurnkeyComponents\Samples\Automation\LaunchVSWithModelCodeGenFullBuildAllAndUploadToMDrivenServer.cmd
The script looks like this:
@echo offsetlocal:: Configurationset "VSSuppressUserAuthentication=true" :: should stop VS from displaying login and halting everythingset "MODELAUTOMATION_URL=TheUrlToTheMDrivenServer"set "MODELAUTOMATION_USER=TheAccountForMDrivenServer"set "MODELAUTOMATION_PWD=ThePWDForMDrivenServer"set "LOGFILE=C:\Users\hkarlsen\source\repos\MDriven Solution Template1\MDRIVENAUTOMATIONRESULT.log"set "MODELFILE=C:\Users\hkarlsen\source\repos\MDriven Solution Template1\MDriven Solution Template1\MDrivenEcoSpaceAndModelNetStandard\MDrivenModel.ecomdl"set "SLNFILE=C:\Users\hkarlsen\source\repos\MDriven Solution Template1\MDriven Solution Template1.sln"set "DEVENV=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe":: Delete old log file if it existsif exist "%LOGFILE%" (echo Deleting old log file...del "%LOGFILE%"):: Launch Visual Studio with model automationecho Launching Visual Studio with model automation..."%DEVENV%" "%SLNFILE%" MODELAUTOMATION="%MODELFILE%":: Wait for Visual Studio to close (optional):: timeout /t 30 >nul:: Display log file contentsecho.echo ===== Automation Result =====if exist "%LOGFILE%" (type "%LOGFILE%") else (echo Log file not found: "%LOGFILE%"")endlocal
You will need to wake up VS with the solution ("%SLNFILE%" standard) and the model (MODELAUTOMATION="%MODELFILE%").
Prior to starting VS, you must set the following env-vars:
MODELAUTOMATION_URL
MODELAUTOMATION_USER
MODELAUTOMATION_PWD
MODELAUTOMATION_OUTPUTDIRECTORY (optional path to where to put log and package output)
MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME (overrides MODELAUTOMATION_OUTPUTDIRECTORY )
MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME (overrides MODELAUTOMATION_OUTPUTDIRECTORY )
A file MDRIVENAUTOMATIONRESULT.log (or MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME) will be produced once VS is finished and automatically quits.
To successfully use this, you must have the MDrivenFramework extension installed in your VS2022. Get the vsix from the download page at MDriven.net
Alternatively
Alternatively, you may set these environment variables:
MODELAUTOMATION_PACKAGEONLY=true
MODELAUTOMATION_PACKAGETAG (optional, ignored when MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME is set)
A file ModelAndCodeForMDrivenServer<MODELAUTOMATION_PACKAGETAG>.zip is then produced along with the MDRIVENAUTOMATIONRESULT.log.
The zip file is what the MDrivenServer expects at this endpoint:
<YourMDrivenServerUrl>/api/ServiceAdmin_WebApi/SubmitNewModelCI
Post multipart bytearray content with basic auth (Authorization header with Basic + base64(username:pwd)). Use a valid MDrivenServer account allowed to upload the model. After it is received, the model is added as the current version and the evolve starts.
After this point, one can poll the status:
<YourMDrivenServerUrl>/api/ServiceAdmin_WebApi/CurrentStatusCI
Get it with basic auth.
Example from powershell
# Define variables
$serverUrl = "<YourMDrivenServerUrl>"
$username = "<your-username>"
$password = "<your-password>"
$modelZip = "C:\Path\To\Model.zip"
# Encode credentials for Basic Auth
$pair = "$username:$password"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$headers = @{ Authorization = "Basic $base64" }
# --- Upload the model ---
Write-Host "Uploading model..."
$response = Invoke-RestMethod -Uri "$serverUrl/api/ServiceAdmin_WebApi/SubmitNewModelCI" `
-Method Post `
-Headers $headers `
-Form @{ file = Get-Item $modelZip }
Write-Host "Upload response:"
$response
# --- Poll the status ---
Write-Host "Polling status..."
$status = Invoke-RestMethod -Uri "$serverUrl/api/ServiceAdmin_WebApi/CurrentStatusCI" `
-Method Get `
-Headers $headers
Write-Host "Current status:"
$status
