This module will test your code as it pushes it to the next environment.
Documentation
Description
This module is used to move code from one environment to the next. The code is tested before it is moved to the next environment. When the code is being moved to production the module schedules a production deployment at midnight, otherwise it is moved immediately.
Typical Usage Scenario
This module should be used anytime you want to test your code before pushing it. It can also be used to make pushing code dependent on your unit tests passing.
Limitations
This module currently only works for applications with acceptance and production environments. It does not support configurations that include a test environment.
Implementing the Module in Your Project
We'll use several environment constants to provide API credentials and to identify environments. Some of these constants are truly constant, with the "default value" used across every environment. Other constants have environment-specific values. We'll also configure security and a couple other items.
Mendix API Config Constants Location: Pipeline / Mendix API These provide configuration for the Mendix deployment API. The path to these constants isPipeline / Mendix API. Make the following changes:
Changethe "AppId"constantto the name of the cloud node for your app. This is also known as the the subdomain. (For example,byu-mylink.mendixcloud.com has an appId of "byu-mylink")
Change the "username"constant to the email address of the user you want to use for the API
Security Go into yourProject Security, then to User Roles. Edit theAdministratorrole and give it these module roles:
Pipeline.Admin
MicroflowScheduler.Configurator
UnitTesting.TestRunner
Give these module roles to any other user role who needs to deploy the pipeline.
The Button This module comes with a button that calls the main microflow (BTN_Pipeline_Begin),executing the pipeline. We recommend you use this pre-built button when implementing your pipeline. Find, copy, and paste the button from this empty page:USE_ME/Button_Pipeline_Begin. You can always use your own way to call the main microflow. However, this particular button is handy because:
It is conditionally visibleonlyin environments "Local" or "Acceptance." It is not visible in Prod because you can't deploy past Prod.
Visible only to the Pipeline module role "Admin"
It asks for confirmation and then brings up a loading bar
When deploying from Acceptance to Prod, it schedules a deployment and then turns into a Cancel button. The Cancel button will cancel that scheduled deployment.
Integrate Landing Page Go toPipeline / _Production_Deployment / ACT_ProductionDeployment_Scheduleand make the following change:
Go to the box that says "Show 'Admin_Overview'"
Change it to thepage that now holds your Pipeline button. This is the page that will be refreshed.
Deploy to All Environments To proceed, we must deploy what we have inacceptanceandproduction.Then we can change Constants and Scheduled Events, specific to those environments.
Change Constant: "Environment_Name" Location:(Change only in Mendix Cloud Portal) This constant is different in every environment. Its default value is already set as "Local", and we want to change it for Acceptance and Production. That way, we can determine which environment we are in from within microflows.
To change a constant for a specific environment, the project must first be deployed to all environments, with this module installed (we did this earlier).
Go to Mendix Cloud Portal and under Deploy select Environments.
Click the Details button for one of the environments (We need to configure both). You may receive an error.
If you didn't get an error, skip this paragraph. This error means your Mendix account lacks the rights on the team that are required to edit these features. The rights can be granted by your team's Technical Contact or App Contact. Contact information for both team members can be found on the Mendix Developer Portal for your project under Apps/"Your Project"/Settings/General.
Now selectModel Optionsand we'll be editing the Constants.
Make these changes:
In the Production Environment, change the constantEnvironment_Nameto "Production"
In the Acceptance Environment, change the constantEnvironment_Nameto "Acceptance"
Scheduled Event: "SE_Scheduler_Q1" Important:Only do this in acceptance.Do not enable the scheduled event in production. Still in App Cloud Services, on the same page as "Constants", go to "Scheduled Events". Make the following change:
In the Acceptance Environment, change the scheduled eventMicroflowScheduler.SE_Scheduler_Q1so that it isenabled.
*********************************************
Now you're done implementing! You should be able to test deploying your pipeline now. Refer to "How to Use" for instructions on using the pipeline.
*********************************************
How to Use
Pull Request
Before deploying to acceptance, you must have your code reviewed.
If you have made major changes you must have the code reviewed by a supervisor.
For example if your changes affect multiple parts of the website, change something fundamental, there is high risk of errors, or they deal with sensitive data.
If your change is minor you should have the code reviewed by a nearby team member.
For example if it only touches an isolated part of the website, or it is non-fundamental or cosmetic.
Make any necessary changes.
After this process, you may deploy to acceptance.
Local to Acceptance
The pipeline only deploys from the main line.If you are on a branch, merge and commit before deploying.
Important:When the pipeline executes from local, it will deploy themost recently committedversion. When you are ready,you commit and then immediately click Deploy to Acceptance on your running local environment. If you wait ten minutes before deploying another person could commit their code. Clicking Deploy to Acceptance will deployboth commits.
When you click Deploy to Acceptance the site will display a loading bar, and gray out the rest of the screen. It may take a few minutes.
If unit tests fail it will stop everything and tell you to ensure that the unit tests pass.
If tests pass it will continue with the pipeline process.
Pipeline errors will produce an error message.
If it finishes with no errors you will see a success message
Acceptance-to-Production
This grabs the package currently on Acceptance, and deploys the package to production.
When you click Deployto Production it will run unit tests like before. When these are complete,it schedules the rest ofthedeployment to occur at midnight.
When the microflow ends, it shows a message, and there will be nothing else on the screen to see for now.
The deployment microflow will occur at midnight.
Architecture
This is an overview of how the microflows work together and how the project file structure is ordered.
Microflow Structure
Preparation
The microflow that calls the pipeline is: 1_Pipeline Begin /BTN_Pipeline_Begin.
It checks value of the constant "environment" and executes a different microflow, depending on each environment.
There are a few external modules that must be part of your project because the Pipeline uses them. Below we will show you how to configure these modules.
Microflow Scheduler Once you have imported it, go into its domain model. Make the following changes:
Addattributesto MicroflowScheduler.Schedule
"PackageId_Acceptance" (String (200))
"PackageId_Production" (String (200))
"Result" (Enumeration)
Set the Enumeration as Pipeline / Package Deploy / Enumerations / DeploymentResult
"FinishedTime" (Date and Time)
"Pipeline" (Boolean, set default to 'false')
Add anassociationbetween [Pipeline.Environment] * and 1 [MicroflowScheduler.Schedule]
You'll have to start from Pipeline.Environment domain model, to complete this action
UnitTesting This may already be included in your project. If it isn't, go into the CONFIG folder in the UnitTesting module. Make the following change:
When all of these modules are set up, go into yourProject Settings > Runtime > After Startup. Set the microflow to: [UnitTesting._USE ME / Microflows /Startup]. If you already have a startup microflow, andyou nowneed to call both,then create a microflow that calls both of them and use this as your startup microflow.
Resolve Errors
Some of your newly installed modules may containdeprecated elements. These will show up as errors. None of the pages listed above are directly used in the Pipeline module. Delete these pages or if you want to keep them, copy the "good" elements to your own blank page, and delete the old pages.
Installation
Download the module here. It will save as Pipeline.mpk
Note: If you are using Mendix Studio Pro 8.8.* or 8.9.* downloading private app store modules/widgets was turned off due to security concerns. All the BYU Private App Store content can still be downloaded from the Company Content page in the Mendix App Store and then imported into those versions of Studio Pro. Upgrading to a newer version of Mendix Studio Pro fixes the problem.
After the download finishes, import CI/CD Pipeline Plus into your project.
Right click on your Project Explorer
Select Import Module Package
Select the module you just downloaded and click Open