Patch web.config with Development after each deploy
This commit is contained in:
+27
-1
@@ -63,8 +63,34 @@ pipeline {
|
|||||||
bat """
|
bat """
|
||||||
C:\\Windows\\System32\\inetsrv\\appcmd stop apppool /apppool.name:%APP_POOL%
|
C:\\Windows\\System32\\inetsrv\\appcmd stop apppool /apppool.name:%APP_POOL%
|
||||||
xcopy /E /Y /I "%PUBLISH_DIR%\\*" "%DEPLOY_DIR%\\"
|
xcopy /E /Y /I "%PUBLISH_DIR%\\*" "%DEPLOY_DIR%\\"
|
||||||
C:\\Windows\\System32\\inetsrv\\appcmd start apppool /apppool.name:%APP_POOL%
|
|
||||||
"""
|
"""
|
||||||
|
// Patch web.config to set Development environment — must survive every deploy
|
||||||
|
powershell '''
|
||||||
|
$path = "C:\\inetpub\\wwwroot\\web.config"
|
||||||
|
$xml = [xml](Get-Content $path)
|
||||||
|
$aspNetCore = $xml.configuration.location.'system.webServer'.aspNetCore
|
||||||
|
|
||||||
|
# Ensure environmentVariables element exists
|
||||||
|
if (-not $aspNetCore.environmentVariables) {
|
||||||
|
$envVarsNode = $xml.CreateElement("environmentVariables")
|
||||||
|
$aspNetCore.AppendChild($envVarsNode) | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove existing ASPNETCORE_ENVIRONMENT entry if present
|
||||||
|
$existing = $aspNetCore.environmentVariables.environmentVariable |
|
||||||
|
Where-Object { $_.name -eq "ASPNETCORE_ENVIRONMENT" }
|
||||||
|
if ($existing) { $aspNetCore.environmentVariables.RemoveChild($existing) | Out-Null }
|
||||||
|
|
||||||
|
# Add fresh entry
|
||||||
|
$envVar = $xml.CreateElement("environmentVariable")
|
||||||
|
$envVar.SetAttribute("name", "ASPNETCORE_ENVIRONMENT")
|
||||||
|
$envVar.SetAttribute("value", "Development")
|
||||||
|
$aspNetCore.environmentVariables.AppendChild($envVar) | Out-Null
|
||||||
|
|
||||||
|
$xml.Save($path)
|
||||||
|
Write-Host "web.config patched: ASPNETCORE_ENVIRONMENT=Development"
|
||||||
|
'''
|
||||||
|
bat 'C:\\Windows\\System32\\inetsrv\\appcmd start apppool /apppool.name:%APP_POOL%'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
failure {
|
failure {
|
||||||
|
|||||||
Reference in New Issue
Block a user