Domanda

Stiamo usando TeamCity e Octopus Distribuisci per eseguire CI / CD con WSP personalizzati che usiamo per SharePoint e attualmente sto cercando di risolvere il problema di come gestire la configurazione specifica per l'ambiente.

Considera lo scenario in cui abbiamo un WSP e aggiundiamo ad esso una parte web che dipende da un servizio Web esterno.Ho dev, test e ambienti di produzione, e ciascuno ha un URL diverso per questo servizio web.Dove / come dovrei memorizzare l'URL e come posso impostare in modo che non siano necessarie fasi manuali per ottenere il valore corretto salvato in ciascun ambiente?

Preferirei non dipendere da nulla preesistente sul server (impostazione del registro, nome dell'ambiente in una borsa di proprietà, ecc.) Come vorrei che i miei wsp siano il più autosufficienti possibile.

È stato utile?

Soluzione

I do not know Octopus Deploy, but I briefly tried TeamCity for this same purpose. The way we did it was to create Environment Variables per build configuration where we set the properties like Server URL etc.

When deploying we used PowerShell scripts that took parameters and in TeamCity, when calling this script we handed off the Environment Variable to it.

This way, your scripts stay generic (not specific to one server) and you can easily configure and reuse the Environment Variables for different Build Configurations (LAB\TEST\PROD).

EDIT: Let's get this variables all the way to your custom code

Now that you've handed off these variables to your deployment scripts, some of them will probably be used during deployment but others may only be needed at runtime of your code. In this case it's very common to use the Property Bag. Easy to set and read from at any time you have access to a SharePoint Context object.

Altri suggerimenti

I'm currently leaning towards a solution involving a custom SPPersistedObject, as described here.

You create your own class that derives from the SPPersistedObject and add your settings as properties to the class and marks them with the Persisted attribute.

public class TheSettings: SPPersistedObject {
    public TheSettings() {}

    public TheSettings(string name, SPPersistedObject parent, Guid id) 
        : base(name, parent, id) { }

    [Persisted]
    public string WebServiceUrl;
}

Then you use the SPWebApplication GetChild method to retrieve your settings.

TheSettings settings = webApplication
    .GetChild<TheSettings>("theSettings");

I usually add two static methods to my settings class for easy creating and retrieval of settings:

public static TheSettings GetSettings(SPWebApplication webApplication) {
    TheSettings settings = webApplication.GetChild<TheSettings>("theSettings");
    if(settings == null) {
        return TheSettings.CreateNew(webApplication);
    }
    return settings;
}
public static TheSettings CreateNew(SPWebApplication webApplication) {
   return new TheSettings("theSettings",  webApplication, Guid.NewGuid());
}

I could create a custom Feature Receiver which has the ability to set different settings in different environments, but I still need some way at activation time to tell it which environment to use.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top