Each time we deploy a latest release branch of an app to one of our environments (test, acceptance, production), before restarting the application we need to update constants in the sprinter that have changed in the development process. Mendix created the Deploy API for this to do this programmatically using PowerShell (https://docs.mendix.com/apidocs/deploy-api#set-environment-settings) using the 'Set Environment Settings' HTTP Post Call.
We are trying to implement constants setting programmatically using Powershell, however the set-constants function does not seem to update the constants in the sprinter and neither return an error.
The functions are defined as follows (also see the Deploy API documentation):
Function Get-Constants($headers, $url, $appname, $environment) {
irm -Headers $headers ${url}apps/$appname/environments/$environment/settings/ -ContentType "application/json"
}
Function Set-Constants($headers, $url, $appname, $environment, $appsettings) {
$updatedConstants = irm -Headers $headers -ContentType "application/json" -Body $appsettings -Method Post -Uri ${url}apps/$appName/environments/$environment/settings/
return $updatedConstants
}
We use these function in the following code to demonstrate where the Set-Constants function does not seem to update constants in the Sprinter. Codelines include additional explanation.
$appname = 'coreql'
$environment = 'Test'
$appSettings = Get-Constants $headers $url $appname $environment # <- 1.
$appSettings.GetType() # <- 2.
$appSettings.Constants # <- 3.
$appSettings.Constants[$appSettings.Constants.Name.IndexOf('UnitTesting.RemoteApiEnabled')].Value = $true # <- 4.
$result = Set-Constants $headers $url $appname $environment $appSettings # <- 5.
$result.Constants[$result.Constants.Name.IndexOf('UnitTesting.RemoteApiEnabled')].Value # <- 6.
$appSettingsNew = Get-Constants $headers $url $appname $environment # <- 7.
$appSettingsNew.Constants[$appSettingsNew.Constants.Name.IndexOf('UnitTesting.RemoteApiEnabled')].Value # <- 8.
# 1. This function works properly and returns all constants for the coreql app on the test environment
# 2. Returns type System.Object with name PSCustomObject
# 3. Displays us all the constants available for this app on this environment
# 4. One of the Boolean constants we explicitly change from $false to $true here
# 5. Here we use the modified $appSettings to set constants in the sprinter through the API and get a result back
# 6. Here if we look at the constant, it's value is STILL $false, WHILE $true EXPECTED
# 7. We again retrieve the constants from the sprinter using the Get-Constants function
# 8. We observe the constant value is STILL $false, WHILE $true EXPECTED
The variables $headers and $url work fine for the Get-Constants, so they are not displayed in the above code and are well defined.
Though we tried already more variants of the Invoke-RestMethod (or ‘irm’) in the Set-Constants function, we could not get it to work in any way.
I hope anyone can help us with the question why the Mendix Deploy API does not Set-Constants here.
Kind regards,
Jeroen Moonen