Monday, 28 November 2011

Script to Automate the WSP deployment and to activate features

This post is regarding the usage of a simple script to automate the wsp installation and featue activation. Whenever we want to deploy components like custom web parts,  custom user control and custom application pages etc. we use sharepoint solution packages for deployment and then we activate the respective features manually. It is a tediou job to install the wsps and  activate the features manually, if we have multiple solution packages to be deployed. To automate this, we can use the the following script to install wsp and activate features.

 :begin
@echo off

set solutionName=Custom.MyTask
set SolutionPath=D:\Custom\Custom.MyTask.wsp
set featureSampleFeature1=Custom.MyTask
set featureSampleFeature2=Custom.MyTaskWPDeployment
set featureSampleFeature3=Custom.MyTask.WebConfigChange

rem ** Replace this value with the URL of your site **
@set url=http://vsalbtstwfe10:10110


@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%path%

stsadm -o retractsolution   -name %solutionName%.wsp -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name %solutionName%.wsp -override

echo Adding solution %solutionName% to solution store...
echo ----------------------------------------------------

stsadm -o addsolution -filename %SolutionPath%
if errorlevel == 0 goto :deploySolution

echo ### Error adding solution %solutionName%
echo .
goto end

:deploySolution
echo Deploying solution %solutionName%...
echo ----------------------------------------------------
stsadm -o deploysolution -name %solutionName%.wsp -url %url% -immediate -allowGacDeployment -allowCasPolicies  -force
stsadm -o execadmsvcjobs

if errorlevel == 0 goto :activateFeature

echo ### Error deploying solution %solutionName%
echo .
goto end

:activateFeature

echo Activating feature %featureSampleFeature1% in solution %solutionName%...
echo ----------------------------------------------------

stsadm -o activatefeature -name %featureSampleFeature1% -url %url% -force

echo Activating feature %featureSampleFeature2% in solution %solutionName%...
echo ----------------------------------------------------

stsadm -o activatefeature -name %featureSampleFeature2% -url %url% -force


echo Activating feature %featureSampleFeature3% in solution %solutionName%...
echo ----------------------------------------------------
stsadm -o activatefeature -name %featureSampleFeature3% -url %url% -force

if errorlevel == 0 goto :success

echo ### Error activating features
echo .
goto end

:success
echo Successfully deployed solution and activated feature(s)..
echo .
goto end

:end
pause


No comments:

Post a Comment