Continuous integration (CI) is the process where the build/evolve/deploy process is automated but 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 also is 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 build prior to upload for use with CodeDress
- Upload to MDrivenServer - to initiate the evolve och the database
A few news has been added to the MDrivenFramework extension of VS2022 to facilitate these steps.
An example script can be found in our GitHub respository: 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)
A fileMDRIVENAUTOMATIONRESULT.log will be produced once VS is finished and auto 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)
A file ModelAndCodeForMDrivenServer<MODELAUTOMATION_PACKAGETAG>.zipis then produced along with the MDRIVENAUTOMATIONRESULT.log
The zip file is what the MDrivenServer expects on this endpoint:
<YourMDrivenServerUrl>/api/ServiceAdmin_WebApi/SubmitNewModelCI
Post with Multipart bytearray content with basic auth (Authorization header with Basic + base64(username:pwd)). Use a valid MDrivenServer account allowed to upload model. After received the model is added as current version and evolve starts.
After this point one can poll the status:
<YourMDrivenServerUrl>/api/ServiceAdmin_WebApi/CurrentStatusCI
Get with basic auth.
