MS Web Deploy Ignoring <setParameter> Entries + Writing to wrong file

Viewed 493

Problem

  1. We have 3 parameters required to authenticate with our 3rd party service: username, password, securityToken which live in unexpected places (depending on environment they could be in Web.config or CI build scripts).
  2. We're asking MS Web Deploy to write <setParameter> values from our XML files but it's ignoring some... specifically the username, password and security token parameters
  3. MS Web Deploy wants to write to \Views\Web.config. We want to write to \Web.config.

2 Goals

  1. Organize all of our authentication credentials in to DeploySettings.xml files respective to each or our environments (dev, qa and production).
  2. Write <setParameter> values to \Web.config not \Views\Web.config

Details

  • We're uisng Jenkins for continuous integration.
  • Jenkins is calling MS Web Deploy 3 to handle the deployment.
  • We're going to have a DeploySettings file for each environment.
  • I'm currently working on our dev environment. For the scope of this question, I'll be referring to our "dev" environment and it's respective DeploySettings.Dev.xml file
  • The Jenkins deploy script tells web deploy to use -setParamFile to overwrite \Web.config values with <setParameter> values from the DeploySettings.Dev.xml file

Deploy Script calling for DeploySettings file

-setParamFile:"%WORKSPACE%\DeploySettings.Dev.xml" -verbose

DeploySettings.Dev.xml

⚠️ This is not the entire file

<?xml version="1.0" encoding="utf-8"?>
<parameters>
  <setParameter 
    name="username" 
    value="lukeSkywalker" />
  <setParameter 
    name="password" 
    value="xxxxxx" />
  <setParameter 
    name="token" 
    value="xxxxxx" />
  <setParameter 
    name="DBConnection" 
    value="Data Source=fully.qulified.domain;Initial Catalog=CatalogName;uid=obiwan;password=xxxxx;MultipleActiveResultSets=True" />
  <setParameter 
    name="SessionDBConnection" 
    value="Data Source=1.2.3.4;uid=userId;password=xxxxxx" />
...

Verbose Jenkins Deployment console logging demonstrating that username, password and token are being ignored

note that username, password and token are absent

Verbose: Parameter entry 'DBConnection/1' is applicable to '\Web.config' because of its scope.
Verbose: Parameter entry 'SessionDBConnection/1' is applicable to '\Web.config' because of its scope.

Verbose Jenkins Deployment console logging showing that we're writing to the wrong file (\Views\Web.config)

Verbose: Parameter entry 'DBConnection/1' is applicable to '\Views\Web.config' because of its scope.
Verbose: Parameter entry 'DBConnection/1' could not be applied to '\Views\Web.config'. Deployment will continue with the original data. Details:

Verbose: Parameter entry 'DBConnection/1' is applicable to '\Views\Web.config' because of its scope.
Verbose: Parameter entry 'DBConnection/1' could not be applied to '\Views\Web.config'. Deployment will continue with the original data. Details:

Burning Questions

  • How do I configure Web Deploy to write to \Web.config? \Views\Web.config is wrong
  • How to configure -setParamFile to fetch and overwrite username, password and token?

Thanks for your time.

1 Answers

Problem Solved

I moved this type of config-rewrite work in to the build script (Jenkins > "Your Project " > Build > Configure).

Here's an example of how I got it to work

SET PATH=%PATH%;c:\Program Files (x86)\IIS\Microsoft Web Deploy V3
msdeploy.exe -verb:sync -source:dirPath="%WORKSPACE%\" ^
  -dest:package="%WORKSPACE%\ArtifactName-%BUILD_NUMBER%.zip" ^
  -replace:objectName=dirPath,targetAttributeName=path,match="^C:\\.*\\pathToSite",replace="c:\sitesRoot\pathToSite" ^
  -declareParam:name=DBConnection,kind=XmlFile,scope=Web.config,match=//configuration/connectionStrings/add/@connectionString,defaultValue="Data Source=1.2.3.4;Initial Catalog=dbName;uid=website;password=xxxx;MultipleActiveResultSets=True" ^
  -declareParam:name=SessionDBConnection,kind=XmlFile,scope=Web.config,match=//configuration/system.web/sessionState/@sqlConnectionString,defaultValue="Data Source=1.2.3.4;uid=xxxx;password=xxxx" ^
  -declareParam:name=Parameter1,kind=XmlFile,scope=Web.config,match=//configuration/appSettings/add[@key="Parameter1"]/@value,defaultValue="paramValue1" ^
  -declareParam:name=Paramtere2,kind=XmlFile,scope=Web.config,match=//configuration/appSettings/add[@key="Parameter2"]/@value,defaultValue="paramvalue2" ^
Related