Uploaded by Felipe Andrés Giraldo Arboleda

Continuous Deployment with Jenkins & .NET The Couchbase Blog

advertisement
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
 Search
(https://blog.couchbase.com/)
Continuous Deployment with Jenkins & .NET
(https://blog.couchbase.com/author/martin-esmann/) Martin Esmann, Developer Advocate, Couchbase
(https://blog.couchbase.com/author/martin-esmann/) on January 8, 2016
This is the first blog post of two about Jenkins and Couchbase. This first post is a general introduction to
Continuous Deployment with Jenkins and .NET. The second blog post will be focusing more on how to
use Jenkins to set-up test data in Couchbase before running your test code.
As a .NET developer you are probably using Visual Studio. Hitting F5 in Visual Studio compiles the
source code and starts the debugger. If you are like me you will hit F5 many times during development
and bug hunting.
But what happens when the code is ready for prime time? Deployment happens!
When I needed to publish an application I often choose the laziest option: manually copying the
executable to the destination, manually installing and manually starting the application.
SHARE
It’s “fun” the first few times, but in the end it gets really difficult; particularly keeping track of changes and
manual updates/deployments. To be honest, this manual approach does not scale very well: it takes
unnecessary time and it’s prone to human errors in the deployment process.
A more mature option would be to have an automated infrastructure to handle deployment. Such
infrastructure is often referred to as Continuous Integration/ Continuous Deployment.

Using Continuous Integration/Continuous Deployment, enables a workflow like this:
 Code, build and test locally on your dev. box (as usual)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)

(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
1/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Check source code in to a development branch in your favourite Source Control Management
System.
Optional code review by team members.
Merge your changes to the main (release) branch.
The CI Server will detect the changes to the main branch and download, compile and deploy/install
your application on the release server.
There are no manual steps: it’s all scripted and automatic.
Continuous Deployment
You can choose from a number of Continuous Integration/Deployment (CI) tools, each with its own
caveats. In my set-up I need a CI Server that understands the components in my application.
So let’s take a closer look at my application architecture and components:
Platform: .NET 4.5.2
IDE: Visual Studio 2015 (MSBuild files)
Application type: Windows Service
NuGet: Package Manager used for all references.
Source Control: Git (github.com)
The CI Server should be able to understand all components mentioned above and (as I’m lazy) it should
be really easy to maintain and set up.
I did a bit of research and from other people’s experiences and blog posts I found that Jenkins seemed
SHARE
to suit
my needs best.
Jenkins

Jenkins is a build server with a plugin architecture that allows the community to extend what Jenkins can
This architecture makes it easy to extend Jenkins to support MSBuild files, Git version
“understand”.
control etc.



Meet Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
S
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
2/23
16/7/2018
Set-up
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Jenkins is installed on a build server. In my set-up the build server is the same as the release server, but
this can be configured differently.
Download and install Jenkins for your platform here: https://jenkins-ci.org/
After installation Jenkins is available on its default port: http://localhost:8080/ (http://localhost:8080/)
Con gure Jenkins
Jenkins has plugins for understanding Git repositories, MSBuild files and various other technologies. In
the current set-up we only need to extend Jenkins with those two plugins.
Install the Git Plugin for Jenkins:
1. Open Jenkins, http://localhost:8080/ (http://localhost:8080/)
2. Navigate to “Manage Jenkins”
3. Navigate to “Manage Plugins”Direct link: http://localhost:8080/pluginManager
(http://localhost:8080/pluginManager)
4. Use the “filter” box to search for “Git plugin” and install the plugin.
Install the MSBuild Plugin for Jenkins:
1. Open Jenkins, http://localhost:8080/ (http://localhost:8080/)
2. Navigate to “Manage Jenkins”
3. Navigate to “Manage Plugins”Direct link: http://localhost:8080/pluginManager
(http://localhost:8080/pluginManager)
SHARE
4. Use the “filter” box to search for “MSBUILD plugin” and install the plugin.






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
3/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Jenkins now understands MSBuild files and Git source control, but we still need to configure the
MSBuild Plugin with a path to the msbuild.exe we would like to use.
MSBuild con guration
When the MSBuild plugin was installed it added its own configuration options to the Jenkins global
configuration page.
1. Navigate to http://localhost:8080/ (http://localhost:8080/)
2. Click “Manage Jenkins”
3. Click “Configure System”
4. Scroll down the list until you find “MSBuild”
5. Click the “MSBuild installations…” button
6. Click “Add MSBuild”
7. Give the new MSBuild configuration a name like “MSBuild-default”.
8. In the path field, insert the fully qualified path to msbuild.exeOn my server the path is: C:Program
Files (x86)MSBuild14.0Binmsbuild.exe, but this can be different on your system.Read below for
more information about MSBuild and how to install it.
9. Click save.
SHARE





MSBuild installation
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
4/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
MSBuild is installed with Visual Studio, it’s the build system that Visual Studio uses when you select
“build” or hit “F5”.
It’s not always feasible or even possible to install Visual Studio on your build machine. This could be due
to license and security issues etc.
To accommodate this Microsoft has released a separate package called: “Microsoft Build Tools 2015”
that contains all you need for for using MSBuild.
Direct download: https://www.microsoft.com/en-us/download/details.aspx?id=48159
(https://www.microsoft.com/en-us/download/details.aspx?id=48159)
After successful installation you have MSBuild available on the build server and with that you get the
path value for step 8, above.
With this step done Jenkins is ready to build and deploy with MSBuild and Git.
Create a new Jenkins build project
It’s now time to point Jenkins to the source code and start building.
1. Open Jenkins, http://localhost:8080/ (http://localhost:8080/)
2. Select “new”.Direct link http://localhost:8080/view/All/newJob (http://localhost:8080/view/All/newJob)
3. Give the project a name “Windows Service Deployment” or something you can remember.
4. Select “Freestyle project”.
5. Select “Ok”.
SHARE






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
5/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
SHARE
6. Next, expand the “Source Code Management” region by selecting “Git”.





(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
6/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
7. Complete the Git configuration by filling in the blanks with a URL to your repository and optionally
credentials (if needed).Jenkins can also work with branches. In this set-up I will leave the branch as
the default (Master) but you can select whatever fits your needs.If you don’t already have a Git
repository ready for testing, you can use the pre-cooked repository here:
https://github.com/martinesmann/jenkins-ci-template (https://github.com/martinesmann/jenkins-citemplate)
The source code contains a few more files than your average “Hello Windows Service” solution. I will
explain relevant parts later on as they are used. For now we will just treat this as a “Hello World”
solution.
8. If you haven’t done so already, click “Save” to persist your changes and navigate back to the main
“Project” page.
Testing the Git con guration
Now we can test if the Git Source Management tab has been configured correctly and that we can clone
the source code.
We are not yet building anything, only cloning the source. Building will come in a moment. First, let’s
make sure Jenkins can clone the source from the repository.
1. Navigate to the “Project” page
2. Click the “Build Now” to start a “Build”.
SHARE






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
7/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
3. In the “Build History” region you should now see a build in progress with the name “#1”.
4. If every completes as expected “SUCCESS” then the bubble maker stays blue, if not it goes red.
5. To see the build details, click the build number “#1”
6. Then click “Console Output”. You should see something similar to what I have here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Started by user anonymous
Building in workspace C:Program Files (x86)JenkinsjobsWindows Service deploymentworkspace
Cloning the remote Git repository
Cloning repository https://github.com/martinesmann/jenkins-ci-template
> git.exe init C:Program Files (x86)JenkinsjobsWindows Service deploymentworkspace # t
Fetching upstream changes from https://github.com/martinesmann/jenkins-ci-template
> git.exe --version # timeout=10
> git.exe -c core.askpass=true fetch --tags --progress https://github.com/martinesmann/
> git.exe config remote.origin.url https://github.com/martinesmann/jenkins-ci-template
> git.exe config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeo
> git.exe config remote.origin.url https://github.com/martinesmann/jenkins-ci-template
Fetching upstream changes from https://github.com/martinesmann/jenkins-ci-template
> git.exe -c core.askpass=true fetch --tags --progress https://github.com/martinesmann/
> git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision db11bee4586694774f21e9f38b57af8535c88e1e (refs/remotes/origin/maste
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f db11bee4586694774f21e9f38b57af8535c88e1e
First time build. Skipping changelog.
Finished: SUCCESS
*What’s important to note here is the path to the “workspace” as this is where the source code is
downloaded to and built from. This knowledge can be very helpful when debugging the CI setup.*
Building the source
The next step is to compile and build the source code.
1. Navigate to the “project” page
2. Select “Configure”
SHARE
3. Find the “Add build step”






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
8/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
4. Select the “Build a Visual Studio project or solution using MSBuild”.We need to configure a few
values here:
1. First, select the MSBuild version (we configured this in a previous step).
2. Then give the path to the *.sln or *.proj file for your project.For the pre-cooked repository the path
is: srcMyWindowsServiceMyWindowsServiceDeploy-Windows-Service-ViaMSBuild.projPlease note: We are not pointing to the solution file, rather we are pointing to a
custom MSBuild file that is in the project. This MSBuild file is handling all steps involved with
compiling and deploying the Windows Service.
If you are using the pre-cooked repository, your setup should look like this:
3. Click save
NuGet package restore
If we were to build the project right now it would fail due to missing NuGet packages. Therefore we need
SHARE
to restore the NuGet packages before attempting to build the source.
nuget.exe makes this task very easy, we simply need to fire this command on the solution file:

nuget restore "path to *.sln" file
No surprise Jenkins can handle multiple build steps, so let’s add a build step to enable NuGet restore.

1. Navigate to the “project” page.
2. Select “Configure”.
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)

(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
9/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
3. Find the “Add build step”.
4. Click “Add build step”.
5. Select “Execute Windows batch command”.
6. Re-arrange the build order by dragging the new build step to the top.
SHARE



7. In the Command field insert:nuget restore srcMyWindowsService
8. Click “Save”.
We are now ready to build the project!
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
10/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
The nal test! Primetime!
1. Navigate to the project page
2. Click the “Build now” link
3. Wait for the build to complete
4. Open “Windows Explorer” and navigate to C:
5. Confirm that the file “MyWindowsService.log” exists
6. Open the file and read the log content.This file was create by our newly installed Windows Service!
7. Check that the Service is installed and running:
1. On Windows open “Services” management window
2. Scroll down to you find the service “My Windows Service (…)”
SHARE



Congratulations! You have now successfully configured Jenkins to download, compile and deploy a
.NET Windows Service! Automation ROCKS!
The source code:
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)

(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
11/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
So far we have not given much attention to the source code, but let’s take a moment to walk through the
repository content and structure.
If you navigate to the repository root at:
https://github.com/martinesmann/jenkins-ci-template (https://github.com/martinesmann/jenkins-citemplate)
you will find all the usual files as README etc. but also a file called nuget.exe.
nuget.exe is the executable used to restore the solution’s NuGet package dependencies. You could
argue whether or not it’s good practice to have binary files in your source control, but in this case it’s a
required dependency for the build system and therefore I have included it.
I have placed nuget.exe in the root, to keep it separated from the actual source code and make it easy
to find when setting up the build in Jenkins.
If we navigate deeper into the repository to src/MyWindowsService/MyWindowsService/
(https://github.com/martinesmann/jenkins-citemplate/tree/master/src/MyWindowsService/MyWindowsService) we find four files that do all the hard
lifting of compiling and installing the Windows Service.
The main entry point file is Deploy-Windows-Service-Via-MSBuild.proj
(https://github.com/martinesmann/jenkins-citemplate/blob/master/src/MyWindowsService/MyWindowsService/MyWindowsService.csproj) it’s a
MSBuild file constructed to, not only, compile the source code; but also: stop, uninstall and start the
Windows Service application. This is achieved by calling the three batch files as needed:
safeServiceDelete.bat (https://github.com/martinesmann/jenkins-citemplate/blob/master/src/MyWindowsService/MyWindowsService/safeServiceDelete.bat),
safeServiceStart.bat (https://github.com/martinesmann/jenkins-citemplate/blob/master/src/MyWindowsService/MyWindowsService/safeServiceStart.bat) and
SHARE
safeServiceStop.bat (https://github.com/martinesmann/jenkins-ci-
template/blob/master/src/MyWindowsService/MyWindowsService/safeServiceStop.bat).
It’s out of the scope for this blog post to explain in detail what each of the four files do, but if you take a
at the files individually I’m sure you will get a very good understanding of their inner workings and
look
how they collaborate.

Windows Service source code can be viewed and edited in Visual Studio to fit your specific needs.
The
sample source given in the repository is very simple and only writes a few entries to a text file (log
The
file) and also “upserts” a document to Couchbase Server:
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)

(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
12/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Service1.cs (https://github.com/martinesmann/jenkins-citemplate/blob/master/src/MyWindowsService/MyWindowsService/Service1.cs)
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.ServiceProcess;
5 using Couchbase;
6 using Couchbase.Configuration.Client;
7
8 namespace MyWindowsService
9 {
10
public partial class Service1 : ServiceBase
11
{
12
bool firstRun;
13
public Service1()
14
{
15
InitializeComponent();
16
}
17
18
protected override void OnStart(string[] args)
19
{
20
firstRun = true;
21
22
Log(
23
LogToCouchbase(new List { "OnStart:", DateTime.Now.ToString() })
24
);
25
}
26
27
protected override void OnStop()
28
{
29
Log(
30
LogToCouchbase(new List { "OnStop:", DateTime.Now.ToString() })
31
);
32
}
33
34
private List Log(List lines)
35
{
36
try
37
{
38
File.AppendAllLines("c:\MyWindowsService.log.txt", lines);
39
}
40
catch (Exception ex)
41
{
42
lines.AddRange(
43
new[] {
44
"Excpetion:",
SHARE
45
ex.Message,
46
ex.StackTrace
47(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
});
48
}
49(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
50
return lines;
51
}
52(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
53
private List LogToCouchbase(List lines)
54(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
{
11
55
try
56(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)
{
57
if (firstRun)
58(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
{
59
var config = new ClientConfiguration
60
{






https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/


13/23
16/7/2018
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 }
{
};
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Servers = new List { new Uri("http://10.0.0.4:8091") }
ClusterHelper.Initialize(config);
}
firstRun = false;
// this will overwrite any old log lines!
var result =
ClusterHelper
.GetBucket("default")
.Upsert(
"MyWindowsService.log.txt",
new
{
id = "MyWindowsService.log.txt",
log = string.Join("n", lines)
}
);
lines.AddRange(
new[] {
"Couchbase result: ",
result.Success.ToString(),
"Document Key: ",
"MyWindowsService.log.txt"
});
}
catch (Exception ex)
{
lines.AddRange(
new[] {
"Excpetion:",
ex.Message,
ex.StackTrace
});
}
}
}
return lines;
If you are new to Couchbase I would suggest taking a look at our .NET tutorial here:
try-cb-dotnet (https://github.com/couchbaselabs/try-cb-dotnet).
SHARE
Create your own
easiest way to create your own self deployable Windows Service using Jenkins would most likely be
The
to clone this repository and change the service code in Visual Studio to your needs.
Thanks for reading!


Posted in: .NET (https://blog.couchbase.com/category/net/), Couchbase Server
(https://blog.couchbase.com/category/couchbase-server/)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
14/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Tagged in: .NET (https://blog.couchbase.com/tag/net/), Continuous Deployment
(https://blog.couchbase.com/tag/continuous-deployment/), Couchase Server
(https://blog.couchbase.com/tag/couchase-server/), Jenkins
(https://blog.couchbase.com/tag/jenkins/)
Posted by Martin Esmann, Developer Advocate, Couchbase
(https://blog.couchbase.com/author/martin-esmann/)
 All Posts (https://blog.couchbase.com/author/martin-esmann/)
2 Comments
Andy Hg
APRIL 19, 2018 AT 5:38 AM (HTTPS://BLOG.COUCHBASE.COM/CONTINUOUS-DEPLOYMENT-WITHJENKINS-AND-NET/#COMMENT-19221)
Nice Post Martin,
Can you please elaborate more on installing the NuGet package restore.
SHARE
As
faar as I know, NuGet package manager requires in Visual Studio to install any packages
will be used in the project.
 which
Once the package is installed DLLs are added in ‘bin’ folder, which will be used in the
 deployment packages.
 So what is the exact use of NuGet package restore here ?



(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
Log in to Reply (https://blog.couchbase.com/wp-login.php?
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)
redirect_to=https%3A%2F%2Fblog.couchbase.com%2Fcontinuous-deployment-with-jenkins-and-


net%2F)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
15/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Brandon (https://github.com/brandonh6k)
MAY 21, 2018 AT 8:28 AM (HTTPS://BLOG.COUCHBASE.COM/CONTINUOUS-DEPLOYMENT-WITHJENKINS-AND-NET/#COMMENT-19262)
Andy,
The nuget.exe Martin references in the post is the command line version of the package
manager built into to VS (it’s available at nuget.org). The typical flow for a CI server is:
* Check out latest code
* Restore packages (command line: nuget restore)
* Compile using MSBuild
When you do a nuget restore, the packages aren’t placed into the bin folder – that’s for the
compiled binaries after build. The nuget dependencies go into a packages directory
(typically at the same level as your solution file) and then MSBuild does all of its magic.
Log in to Reply (https://blog.couchbase.com/wp-login.php?
redirect_to=https%3A%2F%2Fblog.couchbase.com%2Fcontinuous-deployment-with-jenkins-andnet%2F)
Leave a reply
You must be logged in (https://blog.couchbase.com/wp-login.php?
redirect_to=https%3A%2F%2Fblog.couchbase.com%2Fcontinuous-deployment-with-jenkins-andnet%2F) to post a comment.
SHARE






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
Search our blog
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
Search here...
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)



(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
16/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
(https://resources.couchbase.com/c/frost-sullivan-
yes-n?x=C7KOcv)
SHARE






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
17/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
(https://info.couchbase.com/2017_CIO_Survey_Report_LP.html)
(https://resources.couchbase.com/c/relational-no-
SHARE






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
sql-wp?utm_medium=lbhq&utm_source=website&x=Y7B0ca)
11

(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)

Subscribe to Blog via Email
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
E t
il dd
t
b
ib t thi bl
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
d
i
tifi
ti
f
t b
18/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Enter your email address to subscribe to this blog and receive notifications of new posts by
email.
Email Address
Subscribe
RSS
RSS - Posts (https://blog.couchbase.com/feed/)
RSS - Comments (https://blog.couchbase.com/comments/feed/)
Blog Topics
Select Topic
Authors
Alex Popov (https://blog.couchbase.com/author/alex-popov/) (1)
Alexis Roos (https://blog.couchbase.com/author/alexis-roos/) (4)
Ali LeClerc (https://blog.couchbase.com/author/ali-leclerc/) (31)
Anil Kumar (https://blog.couchbase.com/author/anil-kumar/) (16)
SHARE






Anne Obendorf (https://blog.couchbase.com/author/anne-obendorf/) (6)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
Anthony Farinha, Director - GSI & Technology Partners, Couchbase
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/author/anthony-farinha/) (1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
Arun Gupta (https://blog.couchbase.com/author/arun-gupta/) (94)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


Arunkumar Senthilnathan (https://blog.couchbase.com/author/arunkumar-senthilnathan-
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
2/) (1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
19/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Show More 
Follow Us on Twitter
Tweets by @CouchbaseDev
Couchbase Dev
@CouchbaseDev
Rollback Mitigation in Kafka Connector 3.4 Beta dlvr.it/QbljsH
Rollback Mitigation in Kafka Connector 3.4 Beta | T…
In which we introduce beta version 3.4 of the Kafka co…
blog.couchbase.com
4h
Follow Us on Facebook (https://www.facebook.com/Couchbase/)
Couchbase
7K likes
SHARE






Like Page
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
Couchbase
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
hace 4 horas
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
We are sure that you have
already checked out
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
#Couchbase 5.5, but have you
read
this
#N1QL
5.5
feature
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)
booklet yet. Here's your free
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
download! http://bit.ly/2Lku7P3
See Translation
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/


20/23
16/7/2018
See Translation
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
Contact (https://www.couchbase.com/contact)
 (https://www.linkedin.com/company/couchbase)
 (https://www.facebook.com/Couchbase)
 (https://twitter.com/couchbase)
 (https://plus.google.com/+CouchbaseServer)
COMPANY
ABOUT (https://www.couchbase.com/about)
LEADERSHIP (https://www.couchbase.com/leadership)
NEWS & PRESS (https://www.couchbase.com/news-and-press-releases)
CAREERS (https://www.couchbase.com/careers)
EVENTS
SHARE
(https://www.couchbase.com/resources/events)
PRICING (https://www.couchbase.com/subscriptions-and-support)

CONTACT US (https://www.couchbase.com/contact)


SUPPORT
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
21/23
16/7/2018
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
DEVELOPER PORTAL (https://developer.couchbase.com)
FORUMS (https://forums.couchbase.com)
PROFESSIONAL SERVICES (https://www.couchbase.com/services)
SUPPORT LOGIN (https://support.couchbase.com)
TRAINING (https://training.couchbase.com)
QUICKLINKS
BLOG (https://blog.couchbase.com)
DOWNLOADS (https://www.couchbase.com/downloads)
GET STARTED (https://www.couchbase.com/get-started)
ONLINE TRAINING (https://training.couchbase.com/online)
RESOURCES (https://www.couchbase.com/resources)
WHY NOSQL (https://www.couchbase.com/resources/why-nosql)
SECURITY (https://www.couchbase.com/resources/security)
SHARE
GDPR (https://www.couchbase.com/resources/gdpr)



© 2018 Couchbase (http://www.couchbase.com) All rights reserved.
Terms of Use (https://www.couchbase.com/terms-of-service)
Policy (https://www.couchbase.com/privacy-policy)
Privacy
Cookie Policy (https://www.couchbase.com/cookie-policy)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)


(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
22/23
16/7/2018
y(
p
Continuous Deployment with Jenkins & .NET | The Couchbase Blog
p
y)
Marketing Preference Center (https://info.couchbase.com/unsubscribe-or-manage-preferences.html)
SHARE






(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=twitter&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=reddit&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=linkedin&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=facebook&nb=1)
11
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=google-plus-1&nb=1)
(https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/?share=email&nb=1)
https://blog.couchbase.com/continuous-deployment-with-jenkins-and-net/
23/23
Download