THIS IS MY BEST PRACTICE - Have a nice day :-)
First of all Create an AutoDeploy user @OctopusDeploy. Generate an API key and keep it. We use it for connection to OctopusDeploy from your build application server.
Open your pilot choosen Octopus project's processes tab. Edit your existing nuget package deployment step. Change project's nuget feed to "Octopus Server (built-in)" Disable any automatic release and deployment triggers on Octopus.
Add octopack to your solution file, which your working csproj.
Add a nuspec file to your solution's csproj file. It must be same named with the csproj.
Nuspec files section could like this. Don't forget the package ID in nuspec file..
<files>
<file src="obj\**\*.*" exclude="obj\octopacking\**\*.*;obj\octopacked\**\*.*;obj\Release\Package\**\*.*;**\*.pdb;**\*.ps1;**\*.dll.config;**\*.loadtest;_DeveloperNotes;_PublishedWebsites" target="obj"/>
<file src="Deploy.ps1" />
</files>
Also add a deploy.cmd(msdeploy) and deploy.ps1 (custom script) files to your csproj.
Deploy.ps1 could like the following
[string[]]$params = @(
"-setParam:name='IIS Web Application Name',value='" + $iisapplicationname + "'",
"-skip:Directory=^" + $iisapplicationname + "\\App_Data",
"-skip:File=.config$",
"-skip:File=.cmd$",
"-skip:File=.ps1$"
)
$msdeployArgs = [string]::join(' ', $params)
if ($OctopusEnvironmentName -ceq 'Development')
{
.\obj\Release\Myproject.Deploy.cmd /Y /M:localhost ($msdeployArgs) | Write-Output
}
else
{
.\obj\Release\Myproject.Deploy.cmd /Y /M:localhost ($msdeployArgs) | Write-Output
}
Add "iisapplicationname" to your OctopusDeploy project and set the value for your each environments.
The files which we have added to sln, open properties for each file. Change the properties like this.. Copy to output directory DO NOT COPY, Build Action NONE.
You will need a Build server like Jenkins.
Add plugins to your build server, which you must use for your project building and packaging operations. (Git, TFS, Change Assembly version plugin, Msbuild, Nunit, Version number plugin )
Add a folder your build server like "C:\Scripts". And copy the Octo.exe, nuget.exe, nuget.config files this location. Later, you should add custom batch(.bat) files to this location.
Create an empty project for your X project and add your development code repository which build your branch.(you should name your development branch "develop") You must set the credentials for your repository connection.
Trigger the job and check you are sure downloading the correct branch code to the build server workspace.
Edit the same project and add an "Execute windows batch command" step to your build project. Add the following commands for nuget package restore on your build server.
"C:\Scripts\NuGet.exe" restore "%WORKSPACE%\Myproject.sln"
Trigger the job and check the package restore is working on build task console.
Edit the same project. Add "Build a Vİsual Studio Project or solution using MSbuild" Ensure the latest MSbuild version has already installed on the build server.
MSbuild file name:
$WORKSPACE\Myproject.sln
Command line arguments:
/t:Rebuild /p:AutoParameterizationWebConfigConnectionStrings=False
/p:DebugSymbols=false /p:DebugType=None /p:IsAutoBuild=True
/p:CreatePackageOnPublish=true
/p:Configuration=Release;DeployOnBuild=True;PackageLocation=".\obj\Release\Myproject.zip";PackageAsSingleFile=True
/p:RunOctoPack=true /p:OctoPackPackageVersion=%VERSION%-dev
/p:OctoPackPublishPackageToHttp=http://octopus.yourdomain.com/nuget/packages
/p:OctoPackPublishApiKey=API-xxxxxxxxxxxxx
Add a "Execute windows batch command" to your development build & deployment project. And write the followig batch file with parameters.
call "C:\Scripts\JenkinsciDeploy.bat" Myproject %VERSION%-dev OctopusProjectName Development %BUILD_NUMBER% %JOB_NAME%
Copy the following file as this location "C:\Scripts"
cd C:\Scripts
Octo.exe create-release --project %3 --version %2 --packageversion %2 --server http://octopus.yourdomain.com --apiKey API-xxxxxxxxxxx --deployto %4 --progress --force --guidedfailure=False --waitfordeployment --deploymenttimeout=00:30:00 --releaseNotes "Jenkins build [%5] http://jenkins.yourdomain.com:8080/job/%6/%5"
Modify your Jenkins project. Check "Create a formatted version number" option. Environment Variable Name must be named as "VERSION". Version Number Format String should be "${BUILD_YEAR}.${BUILD_MONTH}.${BUILD_DAY}.${BUILDS_TODAY}"
Add your Jenkins project a "Change assembly Version" step. Assembly version must be named like "$VERSION"
Use Poll CSM for building the jenkins project for each check-in. On your code repository, Hook must be enabled for the Project. Or you should scheduled build/deployment settings.
Add a post build step "Email Notification"
Finally you should see results.
You should clone this Build job for different branches and different environments.
Change the versioning formatting from "%VERSION%-dev" to "%VERSION%" or "%VERSION%-hotfix"
Change the branch from "/develop" to "/master" "*/hotfix"
Change the deployment target environment in the "JenkinsciDeploy.bat" batch parameters.
You should use this for any web applications which will be deployed..