<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Najib’s blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/najib/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/najib/feed.xml</link>
    <description />
    <lastBuildDate>Fri, 11 May 2018 20:45:47 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Monitoring Python Applications with Azure App Insights</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/monitoring-python-applications-with-azure-app-insights</link>
      <pubDate>Fri, 11 May 2018 21:36:30 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=1915</guid>
      <description><![CDATA[Overview
In this blog, I will show how you can use Application Insights to monitor your web...]]></description>
      <content:encoded><![CDATA[<h2><strong>Overview</strong></h2>
In this blog, I will show how you can use Application Insights to monitor your web application written in Python using the Flask framework.  The sample code can be found <a href="https://github.com/nzarrari/project-python-flask-webapp.git">here</a>.  To follow along, you should have access to an Azure subscription.  Also your machine should have the following:
<ul>
 	<li>Git client</li>
 	<li>Code editor such as Visual Studio Code</li>
 	<li>Python 2.7</li>
</ul>
<h2></h2>
<h2><strong>Setting-up Application Insights</strong></h2>
<ul>
 	<li>Login to Azure Portal then click on <strong>Create a resource</strong></li>
 	<li>Click on <strong>Development tools</strong>, then select <strong>Application Insights</strong></li>
 	<li>Enter the app insights details as shown below then click create</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts1.bmp">       <img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts1.bmp" alt="" class="alignnone wp-image-2285" width="287" height="378" /></a>

&nbsp;
<ul>
 	<li>Once the resource is created, go to <strong>AppInsightsRG</strong> and click on pythonapp.</li>
 	<li>In <strong>Essentials</strong> copy the <strong>Instrumentation Key</strong> and keep it handy.  We will need that later when we start instrumenting our code.</li>
</ul>
<h2><strong>Downloading the Sample Application</strong></h2>
The sample application we will be using for this demo can be cloned from <a href="https://github.com/nzarrari/project-python-flask-webapp.git">here</a>.  Once the code is downloaded from the repository, you can run it by typing:
<pre>python .\runserver.py</pre>
<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts2.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts2.bmp" alt="" class="alignnone wp-image-2305" width="560" height="409" /></a>

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts3.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts3.bmp" alt="" class="alignnone wp-image-2315" width="539" height="592" /></a>

&nbsp;
<h2><strong>Instrumenting your Python Application</strong></h2>
Install the latest Application Insights Python SDK by running the following command:
<pre>pip install applicationinsights</pre>
Once the SDK is installed place the snippet below at the bottom of __init__.py file.  Make sure you replace  '&lt;YOUR INSTRUMENTATION KEY GOES HERE&gt;' with the key you copied in a previous step
<pre>from applicationinsights.flask.ext import AppInsights
app.config['APPINSIGHTS_INSTRUMENTATIONKEY'] = '&lt;YOUR INSTRUMENTATION KEY GOES HERE&gt;'
# log requests, traces and exceptions to the Application Insights service
appinsights = AppInsights(app)</pre>
Restart the application, launch a web browser and go to the site and click on the various links on the page.  Wait a few minutes, and go to the Application Insights instance, refresh and you should see <strong>HEALTH </strong>metrics updated:

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts4.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts4.bmp" alt="" class="alignnone wp-image-2325" width="428" height="485" /></a>

At this point, we are able to send telemetry from the server.  However, notice that <strong>PAGE VIEW LOAD TIME</strong> metric is not updated.  The reason for that is we are only sending information from the server side.  To get a more complete picture we need to also get the client side to send telemetry to our Application Insights instance.  For that, we will need to inject code in the client side of our web application.

Under <strong>templates</strong> folder, open <strong>layout.html</strong>. in the &lt;head&gt; section of your html template, copy the following JavaScript snippet.  Again, make sure you replace  '&lt;YOUR INSTRUMENTATION KEY GOES HERE&gt;' with the key you copied in a previous step
<pre>&lt;script type="text/javascript"&gt;
var appInsights=window.appInsights||function(config){
function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},r=document,f=window,e="script",o=r.createElement(e),i,u;for(o.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",r.getElementsByTagName(e)[0].parentNode.appendChild(o),t.cookie=r.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)s("track"+i.pop());return config.disableExceptionTracking||(i="onerror",s("_"+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&amp;&amp;u(config,r,f,e,o);return s!==!0&amp;&amp;t["_"+i](config,r,f,e,o),s}),t}({
instrumentationKey: "&lt;YOUR INSTRUMENTATION KEY GOES HERE&gt;"
});
window.appInsights=appInsights;
appInsights.trackPageView();
&lt;/script&gt;
</pre>
Once the client side code is injected, save the file and go to your browser, refresh the page and perform a few clicks.  Wait for a few minutes and go to your Application Insights instance, refresh, and you should see the <strong>PAGE VIEW LOAD TIME </strong>metric updated.

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts5.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts5.bmp" alt="" class="alignnone wp-image-2335" width="390" height="488" /></a>
<h2><strong>Sending Custom Events</strong></h2>
To send custom events from your application, place this snippet at the bottom of <strong>views.py</strong> file
<pre>@app.route('/track_custom_event')
def track_custom_event():
    from applicationinsights import TelemetryClient
    tc = TelemetryClient(app.config['APPINSIGHTS_INSTRUMENTATIONKEY'])
    tc.track_event('ShoppingCartCheckout')
    tc.flush()
    return render_template('index.html')
</pre>
&nbsp;

Also create a control in your main page that would trigger the custom event.  Open <strong>index.html</strong> under template folder and look for &lt;div class="row"&gt; tag.  Replace the content of that section with the following:
<pre>&lt;div class="row"&gt;
  &lt;div class="col-md-4"&gt;
     &lt;h2&gt;Send Custom Event&lt;/h2&gt;
     &lt;p&gt;Press button to send custom event called &lt;b&gt;ShoppingCartCheckout&lt;/b&gt;&lt;/p&gt;
     &lt;p&gt;&lt;a class="btn btn-default" href="{{ url_for('track_custom_event') }}"&gt;Custom Event &amp;raquo;&lt;/a&gt;&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>
Save the file and rerun the application.  Your page should now look like this

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts6.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts6.bmp" alt="" class="alignnone wp-image-2345" width="654" height="374" /></a>

Click on the <strong>Custom Event </strong>button a few times then go to your Application Insights instance.  Under <strong>Metrics Explorer, </strong>click on <strong>Add new chart</strong> and on the <strong>Chart details</strong> make the selection as shown below:

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts7.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts7.bmp" alt="" class="alignnone wp-image-2355" width="224" height="571" /></a>

&nbsp;

The chart on the left side should show the data related to the custom event sent from your application

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts8.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts8.bmp" alt="" class="alignnone wp-image-2365" width="512" height="322" /></a>

&nbsp;
<h2><strong>Sending Custom Metrics</strong></h2>
To send custom metrics from your application, add this snippet of code to your <strong>views.py</strong>
<pre>@app.route('/send_metric')
def send_metric():
    from applicationinsights import TelemetryClient
    tc = TelemetryClient(app.config['APPINSIGHTS_INSTRUMENTATIONKEY'])
    import random
    tc.track_metric('queueSize',  random.randint(0,5000))
    tc.flush()
    return render_template('index.html')
</pre>
&nbsp;

Add this code to your html template as described in a previous section
<pre>&lt;div class="col-md-4"&gt;
   &lt;h2&gt;Send Custom Metric&lt;/h2&gt;
   &lt;p&gt;Press button to send custom metric for &lt;b&gt;queueSize&lt;/b&gt;&lt;/p&gt;
   &lt;p&gt;&lt;a class="btn btn-default" href="{{ url_for('send_metric') }}"&gt;Custom Metric &amp;raquo;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
</pre>
&nbsp;

Reload your application and now it should look like this

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts9.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts9.bmp" alt="" class="alignnone wp-image-2375" width="624" height="306" /></a>

Click on the <strong>Custom Metric </strong>button a few times then go to your Application Insights instance.  Under <strong>Metrics Explorer, </strong>click on <strong>Add new chart</strong> and on the right make the selection as shown below:

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts10.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts10.bmp" alt="" class="alignnone wp-image-2385" width="246" height="623" /></a>

The chart on the left should show the data related to the custom metric sent from your application

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts11.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts11.bmp" alt="" class="alignnone wp-image-2395" width="567" height="361" /></a>
<h2><strong>Reporting Handled Exceptions</strong></h2>
To show an example of handled exceptions sent to Application Insights, let’s create a route that raises random exceptions. Also we will inject the code that will report those exceptions to Application Insights.  Add the snippet below to your views.py file:
<pre>@app.route('/handledException')
def handledException():
    import sys
    import string
    import random
    from applicationinsights import TelemetryClient
    tc = TelemetryClient(app.config['APPINSIGHTS_INSTRUMENTATIONKEY'])
    try:
        randomstring = ''.join([random.choice(string.ascii_letters) for n in xrange(8)])
        raise Exception("Exception {0}".format(randomstring))
    except:
       tc.track_exception()
   
    try:
       randomstring = ''.join([random.choice(string.ascii_letters) for n in xrange(8)])
       raise Exception("Exception {0}".format(randomstring))
   except:
       tc.track_exception(*sys.exc_info(), properties={ 'foo': 'bar' }, measurements={ 'x': 42 })
       tc.flush()
   
   return render_template('index.html')
</pre>
&nbsp;

Add this code to your html template as described in a previous section
<pre>&lt;div class="col-md-4"&gt;
   &lt;h2&gt;Trigger handled Exception&lt;/h2&gt;
   &lt;p&gt;Press button to trigger a random handled exception&lt;/p&gt;
   &lt;p&gt;&lt;a class="btn btn-default" href="{{ url_for('handledException') }}"&gt;Handled Exception &amp;raquo;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
 
</pre>
Click on the <strong>Handled Exception</strong> button a few times then go to your Application Insights instance.  Under <strong>Metrics Explorer, </strong>click on <strong>Add new chart</strong> and on the right make the selection as shown below:

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts12.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts12.bmp" alt="" class="alignnone wp-image-2405" width="239" height="609" /></a>

The chart on the left should show the exceptions sent from your application

<a href="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts13.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/05/appinsghts13.bmp" alt="" class="alignnone wp-image-2415" width="667" height="453" /></a>
<h2><strong>Wrap-up</strong></h2>
We have just shown how you can send telemetry data from a Python application that uses Flask framework.  You can get the complete code from a branch called <strong>instrumented</strong> <a href="https://github.com/nzarrari/project-python-flask-webapp/tree/instrumented">here</a>.  Note that the complete code is refactored so it might not look exactly the same as the steps described above.

I hope this blog was useful.  Please leave your feedback on how future blogs can be improved.]]></content:encoded>
    </item>
    <item>
      <title>Versioning and Deploying Salesforce Metadata using TFS/VSTS</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/versioning-and-deploying-salesforce-metadata-using-tfsvsts-2</link>
      <pubDate>Sat, 05 May 2018 02:45:29 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=35</guid>
      <description><![CDATA[]]></description>
      <content:encoded><![CDATA[]]></content:encoded>
    </item>
    <item>
      <title>Protecting Secrets using VSTS and Azure Key Vault</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/protecting-secrets-using-vsts-and-azure-key-vault</link>
      <pubDate>Sat, 05 May 2018 02:44:08 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=525</guid>
      <description><![CDATA[Context
&nbsp;

If you are building a modern application and are following modern design...]]></description>
      <content:encoded><![CDATA[<h2>Context</h2>
&nbsp;

If you are building a modern application and are following modern design principles, there is a good chance your application is composed of a number of layers and services.  Also, your services might be communicating with one or more databases to persist their data.  For services to communicate with one another and to be able to talk to databases, they need to leverage information that is considered sensitive.  Hackers know too well that this is one area that many teams don’t properly protect and they are always on the lookout to get hold of that information to leverage for attacks.  Sensitive information in this case include:
<ul>
 	<li>Database username and password or connection strings</li>
 	<li>API keys</li>
 	<li>Authentication (i.e. OAuth) tokens</li>
 	<li>Third party service username and password</li>
 	<li>Any other sensitive information your app might need</li>
</ul>
A common practice to handle this kind of information is to put it in a configuration file somewhere.  Although the file will be replaced when it goes to production, this still not recommended for at least the following reasons:
<ul>
 	<li>After the config file is checked in to the version control system, the sensitive information would be exposed</li>
 	<li>When information changes, a deploy might be required for the new changes to take effect</li>
 	<li>Secrets for production environment will need to be stored somewhere where they are properly protected. Sometimes that’s left to the judgement of the secrets maintainer, which might result in secrets being compromised if they are not kept in a secured location</li>
 	<li>Maintaining lifecycle of these secrets might not be easy since they might be scattered all over the place</li>
</ul>
In the remainder of this blog, I will detail an approach that not only help properly store and maintain the lifecycle of your secrets but also how your application can get access to those secrets without being exposed outside of the application.

&nbsp;
<h2>Approach Overview</h2>
&nbsp;

In this walkthrough, I will show how secrets can be securely stored in Azure using a capability provided by Azure called Azure Key Vault.  I will also show how those secrets can be accessed from an application.  The application I will use for this example would be a .NET MVC Web Application.  Finally, I will create a build in VSTS that would include a deploy step that will deploy the application and supply it with the sensitive information – in this case database connection string.

&nbsp;
<h2>Enable your web app to communicate with Azure Key Vault</h2>
<h3></h3>
<h3>Create a sample project</h3>
In this example, we will use the application created by one of Visual Studio Enterprise 2015 templates.  Here are the steps to create a sample project:
<ol>
 	<li>From Visual Studio go to <strong>File</strong> =&gt;<strong> New</strong> =&gt; <strong>Project</strong></li>
 	<li>Select <strong>Template</strong> =&gt; <strong>Web</strong> =&gt; <strong>NET Web Application (.NET Framework) </strong>and click <strong>Ok</strong></li>
 	<li><strong> </strong>Select <strong>MVC </strong>and click <strong>Ok</strong></li>
</ol>
<h3></h3>
<h3>Register app with Azure Active Directory</h3>
In  order for your web application to communicate with the Azure Key Vault, it will need to be registered with Azure Active directory.

Follow the steps described in this <a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-get-started">link</a> to register your app with Azure Active Directory.  The relevant section is titled “<strong>Register an application with Azure Active Directory</strong>”

&nbsp;
<h2>Enable Application to Communicate with Azure Active Directory and Key Vault</h2>
To enable our sample application to communicate with Azure AD and Key Vault we will need to install two Nuget Packages:
<ol>
 	<li>Microsoft.IdentityModel.Clients.ActiveDirectory</li>
 	<li>Microsoft.Azure.KeyVault</li>
</ol>
&nbsp;

You can install those by right clicking on your project an then<strong> Manage NuGet Packages </strong>or by using <strong>Install-Package </strong>command from <strong>Package Manager</strong> Console

Once done, open Web.config file and add the following keys
<pre>&lt;add key ="ClientId" value=""/&gt;
&lt;add key="ClientSecret" value="" /&gt;
&lt;add key="SecretUri" value="" /&gt;
</pre>
Because the database connection string will be retrieved from the Azure Key Vault, &lt;connectionStrings&gt; is no longer needed.  Go ahead and remove that section from Web.config file.

Create a <strong>Util</strong> folder in your project and create a class named <strong>KeyVaultHelper</strong>

&nbsp;
<pre>using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Threading.Tasks;
using System.Web.Configuration;

namespace WebApplication1.Util
{
   public class KeyVaultHelper{
      public static string MySecret { get; set; }
      public static async Task&lt;string&gt; GetToken(string authority, string resource, string scope){
         var authContext = new AuthenticationContext(authority);
         ClientCredential clientCred = new ClientCredential(WebConfigurationManager.AppSettings["ClientId"],
         WebConfigurationManager.AppSettings["ClientSecret"]);
         AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);

         if (result == null)
            throw new InvalidOperationException("Failed to obtain the JWT token");
         return result.AccessToken;
      }
   }
}
</pre>
&nbsp;

Open Global.asax.cs and add the following snippet at the bottom of Application_Start()

&nbsp;
<pre>var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(KeyVaultHelper.GetToken));
var task = kv.GetSecretAsync(WebConfigurationManager.AppSettings["connectionString"]);
task.Wait();
KeyVaultHelper.connectionStringSecret = task.Result.Value;
</pre>
&nbsp;

To read the connection string dynamically, open IdentityModels.cs inside Models folder and replace ApplicationDbContext() with this:

&nbsp;
<pre>public class ApplicationDbContext : IdentityDbContext
{
   public ApplicationDbContext()
      : base(dbConnectionString(), throwIfV1Schema: false)
   {

   }
   
   public static string dbConnectionString(){
      return KeyVaultHelper.EncryptSecret;
   }

   public static ApplicationDbContext Create()
   {
      return new ApplicationDbContext();
   }
}
</pre>
&nbsp;

Finally, we will need to add a PowerShell script that would populate the config values during deploy time.
<ol>
 	<li>Right click on your solution the click Add =&gt; New Project =&gt; Cloud =&gt; Azure Resource Group and give it a name</li>
 	<li>Right click on Scripts folder and select <strong>New Item </strong>then create a file called <strong>SetAzureWebsite.ps1 </strong>and set its content to the following:</li>
</ol>
&nbsp;
<pre>param (
   [string] $AzureWebsiteName,
   [string] $slot,
   [hashtable] $appsettings
)
Set-AzureWebsite -Name $AzureWebsiteName -Slot $slot -AppSettings $appsettings
</pre>
You can remove anything else inside that project

&nbsp;

To deploy the app in Azure, login to Azure and create the following components:
<ul>
 	<li>Web App</li>
 	<li>Database Server</li>
 	<li>Database</li>
</ul>
<h2>Using Key Vault to Store Secrets</h2>
&nbsp;

In this section we will create an Azure Key Vault and create a secret called <strong>connectionString</strong>.  To create an Azure Key Vault:
<ol>
 	<li>Navigate to <a href="https://portal.azure.com">https://portal.azure.com</a></li>
 	<li>Create resource group called mydemoRG</li>
 	<li>Go to <strong>mydemoRG</strong> and create<strong> Key Vault </strong>and give a unique name. In my case I named it <strong>  </strong></li>
 	<li>Once created, click on it and go to <strong>Overview</strong> =&gt; <strong>Secrets =&gt; Add</strong></li>
 	<li>for upload option choose <strong>Manual </strong>and for name enter <strong>connectionstring </strong>and for <strong>value</strong> field set it to the connection string of the database created earlier<strong>. </strong>To obtain the connectionString from database created earlier, click on the database and then go to <strong>Overview </strong>and then click on <strong>Show database connection strings.  </strong>Make sure <strong>{your_username}</strong> and <strong>{your_password}</strong> are replaced with the actual values for your environment before copying to the value of the secret. <strong>  </strong>Once done, you click create.</li>
 	<li>Go back to the key vault you created and click <strong>Overview </strong>then<strong> Principals</strong></li>
 	<li>Click <strong>Add New</strong></li>
 	<li>In <strong>Select principal</strong> type the name you registered earlier with Azure Active Directory</li>
 	<li>For <strong>Secret Permissions, </strong>check <strong>Get</strong></li>
 	<li>Click <strong>Ok </strong>and then <strong>Save</strong></li>
</ol>
<h2><strong> </strong></h2>
<h2>Build and Deploy app using VSTS</h2>
&nbsp;

To build your app using VSTS, you will need to create a Team Project and then push your code to VSTS repository.  Once code is pushed, you can create a build using Visual Studio template with the following steps:

<a href="https://msdnshared.blob.core.windows.net/media/2017/03/vsts.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/03/vsts.bmp" alt="vsts" class="alignnone size-full wp-image-535" width="692" height="551" /></a>

In <strong>Build Solution</strong> step, ensure that MSBuild Arguments field is set to:
<pre>/p:PackageLocation="$(build.sourcesdirectory)" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
</pre>
&nbsp;

In <strong>Azure App Service Deploy</strong>, make sure that the step is pointing to a valid Azure subscription by properly setting <strong>Azure Subscription</strong> field.  App Service name should be set to the name of the web app created in the previous section.

In <strong>Azure PowerShell Script </strong>step make sure that <strong>Script Path </strong>field is pointing to <strong>SetAzureWebsite.ps1.  </strong>In <strong>Script Arguments</strong> field enter:
<pre>-AzureWebsiteName yourwebappname -Slot production -appsettings @{"ClientId" = "your_client_id"; "ClientSecret" = "your_client_secret"; "connectionString" = "your_keyVault_connectionString_url"}
</pre>
Where:

<strong>your_client_id</strong> and <strong>your_client_secret</strong> are the values you obtained when registering your application with Azure Active Directory

<strong>your_keyVault_connectionString_url</strong> can be obtained by going to the Key Vault we created earlier, then clicking on <strong>Secrets </strong>then <strong>connectionstring</strong> secret we created earlier then select current version and then <strong>Secret Identifier.  </strong>Here is an example of this value:"https://myappvault.vault.azure.net/secrets/connectionstring/b546a57aa8eb454f8713007063c2f12f"&gt;https://myappvault.vault.azure.net/secrets/connectionstring/b546a57aa8eb454f8713007063c2guid"

Once done, queue a new build.  When the build is done, navigate to the web app and ensure that application is running correctly.

You can find the sample app here: <a href="https://github.com/nzarrari/keyVaultSample">https://github.com/nzarrari/keyVaultSample</a>

I hope this was helpful.  Please give us feedback and suggestions to improve this post.]]></content:encoded>
    </item>
    <item>
      <title>Deploying Linked ARM Templates with VSTS</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/deploying-linked-arm-templates-with-vsts</link>
      <pubDate>Sun, 22 Apr 2018 19:52:45 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=1345</guid>
      <description><![CDATA[Overview
When dealing with deploying a large number of components in Azure, a single ARM template...]]></description>
      <content:encoded><![CDATA[<h1>Overview</h1>
When dealing with deploying a large number of components in Azure, a single ARM template might be challenging to manage and maintain.  ARM linked templates allow you to make your deployment more modular making the templates easier to manage.  When dealing with large deployments, it is highly recommended to consider breaking down your deployment into a main template and multiple linked templates representing different components of your deployment.

Deploying ARM templates can be performed using a number of methods such as using PowerShell, Azure CLI and Azure Portal.  A recommended approach however is to adopt one of DevOps practices, namely Continuous Deploy.  VSTS is an application lifecycle management tool hosted in the cloud and offered as a service.  One of the capabilities VSTS offers is Release Management.

In this blog I will detail how you can deploy linked ARM templates using Release Management feature of VSTS.  In order for the linked templates to be deployed properly, they will need to be stored in a location that can be reachable by Azure Resource Manager.   A location that fits the bill here is Azure Storage; so we will show how Azure Storage can be used to stage the ARM template files.  I will also show some recommended practices around keeping secrets protected leveraging Azure Key Vault.

The scenario I will walk through here is to deploy VNet with a Network Security Group (NSG) structured as linked templates.  We will use VSTS to show how Continuous Deployment can be setup to enable teams to continuously update Azure with new changes each time there is a modification to the template.
<h1>Creating Azure Storage Account</h1>
<ul>
 	<li>Login to Azure portal and create an Azure Storage account following the steps documented <a href="https://docs.microsoft.com/en-us/azure/storage/common/storage-create-storage-account">here</a>. Specify the parameters as shown below.  Make sure the Name is unique.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/arm1.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/arm1.bmp" alt="" class="alignnone wp-image-1735" width="272" height="675" /></a>
<ul>
 	<li>Once deployment is done, go to the storage account and click on Shared access signature then click on <strong>Generate SAS and connection string</strong>. Copy the SAS token generated and keep it handy as we will use it later</li>
 	<li>Go to the storage account Overview page and then click on <strong>Blobs</strong></li>
 	<li>Add a <strong>Container</strong> called “armartifacts” as shown below</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/arm2.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/arm2.bmp" alt="" class="alignnone wp-image-1745" width="421" height="244" /></a>
<ul>
 	<li>Once the container is created, click on it and go to <strong>Container properties</strong>. Copy the URL field and keep it handy.  We will need it later as well</li>
</ul>
&nbsp;
<h1>Protecting Secrets with Azure Key Vault</h1>
<ul>
 	<li>In the Azure portal, create an Azure Key Vault resource</li>
 	<li>Click on the Azure Key Vault you just created and click on Secrets</li>
 	<li>Click on Generate/Import to add the SAS Token</li>
 	<li>For name, enter “StorageSASToken” and enter the Azure Storage shared access signature key you copied in a previous step to the <strong>Value</strong> field</li>
 	<li>Click Create</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm3.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm3.bmp" alt="" class="alignnone wp-image-1755" width="498" height="457" /></a>

&nbsp;
<h1>Linking Azure Key Vault to VSTS</h1>
<ul>
 	<li>Login to your VSTS account. If you don’t have one, you can create one for free <a href="https://go.microsoft.com/fwlink/?LinkId=307137&amp;clcid=0x409&amp;wt.mc_id=o~msft~vscom~home-vsts-hero~27308&amp;campaign=o~msft~vscom~home-vsts-hero~27308">here</a></li>
 	<li>Go to Build and Release hub in VSTS and click Library</li>
 	<li>In <strong>Variable Group name</strong> field enter “AzureKeyVaultSecrets”</li>
 	<li>Toggle “Link secrets from an Azure key vault as variables”</li>
 	<li>Select your Azure subscription and then the Azure key vault you created earlier and click Authorize</li>
 	<li>Once authorization is successful you can add variables by clicking “Add” and you should be presented with the option to add references to the secrets in the Azure key vault. Once you added the reference to the StorageSASToken, click Save.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm4.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm4.bmp" alt="" class="alignnone wp-image-1765" width="571" height="476" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm5.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm5.bmp" alt="" class="alignnone wp-image-1775" width="569" height="538" /></a>

&nbsp;
<h1>Set-up Continuous Deployment using VSTS</h1>
At this point we should have everything in place to deploy our linked template to Azure.  To setup the deployment pipeline, login to VSTS and click on <strong>Build and Release</strong> then <strong>Releases </strong>then create a release definition.  Select an empty process and name your environment <strong>Production</strong>.  For artifact, point to your GitHub account

<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm6.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm6.bmp" alt="" class="alignnone wp-image-1785" width="886" height="516" /></a>
<ul>
 	<li>To enable Continuous deployment, click on trigger button and toggle <strong>Continuous deployment trigger</strong></li>
</ul>
<strong><a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm7.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm7.bmp" alt="" class="alignnone wp-image-1795" width="882" height="342" /></a> </strong>
<ul>
 	<li>Click <strong>Variables</strong> then <strong>Variable groups </strong>then click on <strong>Link variable group. </strong>Select the <strong>AzureKeyVaultSecrets </strong>variable group that you created in an earlier step</li>
 	<li>Add a variable called AzureBlobStorageURL and paste in the value from the url you copied earlier when you created the Azure Storage account</li>
 	<li>Add a variable called <strong>blobContainerName </strong>and put the name of your Azure blob container</li>
 	<li>Add a variable called <strong>StorageAccountName </strong>and put the name of your Azure storage account</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm8.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm8.bmp" alt="" class="alignnone wp-image-1805" width="882" height="195" /></a>

&nbsp;
<ul>
 	<li>In the release tasks, create the following steps:</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm9-1.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm9-1.bmp" alt="" class="alignnone wp-image-1885" width="875" height="441" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm10.bmp"></a><a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm10.bmp"></a><a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm10-1.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm10-1.bmp" alt="" class="alignnone wp-image-1895" width="887" height="498" /></a>

&nbsp;
<ul>
 	<li>Once steps are added, click save and kick-off a release. The release should finish successfully</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm11.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm11.bmp" alt="" class="alignnone wp-image-1835" width="330" height="308" /></a>

&nbsp;
<ul>
 	<li>Check Azure and you should see the VNet with NSG created</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm12.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Linkedarm12.bmp" alt="" class="alignnone wp-image-1845" width="836" height="252" /></a>

&nbsp;

We have just showed how you can break down your ARM template and make it more modular by transforming it into Linked ARM template.  We have also walked through how you can use VSTS to continuously deploy your linked template and enabling the release process to read the SAS key from Azure Key Vault while deploying the template.

I hope you found this blog useful.  Please leave feedback on how this can be made better.]]></content:encoded>
    </item>
    <item>
      <title>Setting up CI/CD targeting Red Hat OpenShift Kubernetes Using VSTS</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/setting-up-cicd-targeting-red-hat-openshift-kubernetes-using-vsts</link>
      <pubDate>Wed, 03 Jan 2018 15:50:29 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=825</guid>
      <description><![CDATA[Overview
&nbsp;

In this blog, I will detail the steps to deploy a containerized ASP.NET Core Web...]]></description>
      <content:encoded><![CDATA[<h1>Overview</h1>
&nbsp;

In this blog, I will detail the steps to deploy a containerized ASP.NET Core Web api app into an OpenShift Kubernetes cluster.  The reader of this blog is assumed to have basic knowledge on the following topics:
<ul>
 	<li>Containerization with Docker</li>
 	<li>Cluster management and container orchestration using Kubernetes</li>
 	<li>Team Foundation Server (TFS) or Visual Studio Team Services (VSTS)</li>
</ul>
To reproduce the steps detailed in this blog, the following tools are needed:
<ul>
 	<li>Visual Studio 2017 Enterprise Edition</li>
 	<li>Visual Studio Team Services account. You can signup for a free VSTS account <a href="https://www.visualstudio.com/team-services/">here</a></li>
</ul>
The first part of this blog will go over how to create a sample ASP.NET Core web application with Docker support that we will use as our demo app to deploy to the Kubernetes cluster. Then we will go over how VSTS can be used to create a CI build that will build the application, package the build output into a Docker image, then push the image to Docker Hub.  After that we will point you to resources that will show how you can create a test OpenShift Kubernetes cluster.  Finally we will go over how VSTS Release Management can be used to continuously deploy to the OpenShift Kubernetes cluster.  As you might have guessed, this might not be easy to setup.  Luckily the Continuous Integration (CI) and Continuous Deploy (CD) aspect of this is greatly simplified by VSTS as you will see later.  So let’s get to work…

&nbsp;
<h1>Setting up CI for an ASP.NET Core app using VSTS</h1>
&nbsp;

In this section, I will show how you can create a sample ASP.NET application with Docker support.  I will also walk through how to create a Continuous Integration (CI) build for this app using VSTS.  First we will need to create a VSTS team project. To do so, browse to your VSTS instance and create a team project. You can signup for a free VSTS account <a href="https://www.visualstudio.com/team-services/">here</a>
<h2>Creating Sample app</h2>
Let’s create a sample application that we will use going forward.  Go to your Visual Studio 2017 Enterprise Edition and press <strong>File</strong> =&gt; <strong>New</strong> =&gt; <strong>Project</strong> =&gt; <strong>Web</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_1.bmp"><img class="alignnone wp-image-866" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_1.bmp" width="620" height="432" /></a>

&nbsp;

Make sure that <strong>Enable Docker Support</strong> is checked

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_2.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_2.bmp" width="620" height="432" /></a>

&nbsp;

Publish the newly created repository by going to Team Explorer =&gt; Sync

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_3.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_3.bmp" width="620" height="432" /></a>

&nbsp;

Under <strong>Push to Visual Studio Team Services</strong>, click <strong>Publish Git Repo</strong>.

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_4.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_4.bmp" width="620" height="432" /></a>

&nbsp;

Select your VSTS account and click on <strong>Advanced</strong> then pick the team project you created earlier

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_5.0.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_5.0.bmp" width="620" height="432" /></a>

&nbsp;

Click <strong>Publish</strong> <strong>repository</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_6.0.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_6.0.bmp" width="620" height="432" /></a>

&nbsp;

Now you should have the code published in your VSTS instance. You can verify that by logging in to your VSTS team project and browse to Code:

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_7.0.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_7.0.bmp" width="1189" height="781" /></a>

&nbsp;
<h2>Creating Continuous Integration Build using VSTS</h2>
&nbsp;

Go to <strong>Build and Release</strong> and select <strong>Builds </strong>then press <strong>New Definition</strong> button
<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_8.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_8.bmp" width="1189" height="781" /></a>

&nbsp;

You will be presented with a list of templates.  Scroll down and select <strong>Container (PREVIEW) </strong>and click <strong>Apply</strong>

Configure the build step as follows:

For <strong>Agent queue </strong>select<strong> Hosted Linux Preview</strong>

Click on <strong>Get Sources</strong> Step and make sure your repo is selected along with the targeted branch

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_10.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_10.bmp" width="1189" height="781" /></a>

&nbsp;

Add <strong>.NET Core</strong> step three times and configure each task as follows.

The first task, set the <strong>Command</strong> field to <strong>restore </strong>and <strong>project(s)</strong> field to <strong>**/*.csproj</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_11.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_11.bmp" width="1189" height="781" /></a>

&nbsp;

The second task, set the <strong>Command</strong> field to <strong>build </strong>and <strong>project(s)</strong> field to <strong>**/*.csproj</strong> and <strong>Arguments </strong>field to<strong> -c Release</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_12.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_12.bmp" width="1189" height="781" /></a>

&nbsp;

The third task, set <strong>Version</strong> to <strong>2.* (preview)</strong>, the <strong>Command</strong> field to <strong>publish </strong>and <strong>project(s)</strong> field to <strong>**/*.csproj</strong> and <strong>Arguments </strong>field to<strong> -o ./obj/Docker/publish</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_13.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_13.bmp" width="1189" height="781" /></a>

&nbsp;

Click on <strong>Build an image</strong> step.  You can accept the default values for that step.  For <strong>Image Name</strong>, make sure you qualify the image name with your Docker repo i.e yourrepo/name:version.  Otherwise the build will fail.

Click on <strong>Push an image </strong>step.  For <strong>Container Register Type</strong> select <strong>Container Registry </strong>from the dropdown list.

In order, to push to your Docker Hub repository, you will need to configure a Docker Registry connection.  To do so, click on <strong>Manage, </strong>this will take you to a page where you can add the connection to your Docker Hub

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_14.0.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_14.0.bmp" width="1189" height="781" /></a>

&nbsp;

Click <strong>New Service Endpoint</strong> and the select <strong>Docker Registry</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_15.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_15.bmp" width="1189" height="781" /></a>

<strong> </strong>In the Docker Registry form select <strong>Docker Hub </strong>as registry type and enter a connection name and your Docker ID and password as shown below.  If you don’t have a Docker Hub account, you can create one for free <a href="https://hub.docker.com/">here</a>. Once information is entered, click on <strong>Verify Connection </strong>to ensure the information entered is correct.  If connection test is successful click <strong>OK </strong>to save the connection.

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_16.0.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_16.0.bmp" width="460" height="392" /></a>

&nbsp;

Go back to the <strong>Push an image</strong> refresh the <strong>Docker Registry</strong> <strong>Connection</strong> and select the connection you created in the previous step.  You can leave the default values for all the other parameters

For <strong>Image Name</strong> field, make sure you qualify the image name with your Docker repo i.e yourrepo/name:version.  Otherwise the build will fail.

Go back to the process tasks and add a task called <strong>Copy Files </strong>and configure it as shown below

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_17.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_17.bmp" width="1189" height="781" /></a>

&nbsp;

Next add a task called <strong>Publish Artifact </strong>and configure it shown below

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_18.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_18.bmp" width="1189" height="781" /></a>

&nbsp;

Click on <strong>Triggers</strong> tab and ensure that <strong>Enable continuous integration</strong> is checked

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_19.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_19.bmp" width="1189" height="781" /></a>

&nbsp;

Click on <strong>Save &amp; Queue</strong>.

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_20.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_20.bmp" width="1189" height="781" /></a>

&nbsp;

&nbsp;

Click <strong>Save &amp; Queue</strong> in <strong>Save build definition and queue</strong> window.  This will kick-off a build.

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_21.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_21.bmp" width="475" height="508" /></a>

&nbsp;

The build should finish successfully

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_22.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_22.bmp" width="1189" height="781" /></a>

&nbsp;

&nbsp;
<h1>Setting up OpenShift Environment</h1>
&nbsp;

To get access to an Openshift that you can use to follow these steps in this demo, follow the steps in this <a href="https://docs.openshift.org/latest/getting_started/administrators.html#getting-started-administrators">resource</a>.

Once the Openshift is setup, Login using your web portal credentials

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_23.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_23.bmp" width="405" height="118" /></a>

Create a new project by clicking on Create Project button

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_24.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_24.bmp" width="353" height="168" /></a>

Name the project <strong>sample-project</strong> and click create button

&nbsp;

To test your deployment, follow the steps below:
<ul>
 	<li>Install the Openshift Origin CLI from <a href="https://docs.openshift.org/latest/cli_reference/get_started_cli.html">here</a></li>
 	<li>Start Poweshell or command prompt</li>
</ul>
<pre>oc login your_Openshift_url -u youruser -p yourpassword</pre>
<ul>
 	<li>Ensure you are on the right project by running</li>
</ul>
<pre>oc projects</pre>
<ul>
 	<li>If you are not pointing to <strong>sample-project</strong></li>
</ul>
<pre>oc project sample-project</pre>
<ul>
 	<li>Create a file called samplewebapp-oc-deploy.yml in your current directory and fill it with the following</li>
</ul>
&nbsp;
<pre>apiVersion: v1
kind: DeploymentConfig
metadata:
  name: sampleapp-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: sampleapp-deployment
    spec:
      containers:
      - image: "yourrepo/samplewebapp:versionnumber"
        name: samplewebapp
        ports: 
        - containerPort: 80
</pre>
Make sure image above points to a valid Docker image
<ul>
 	<li>Deploy the app</li>
</ul>
<pre>oc apply -f samplewebapp-oc-deploy.yml</pre>
<ul>
 	<li>Create a service for the deployment</li>
</ul>
<pre>oc expose deploymentconfig sampleapp-deployment  --port 80 --type=LoadBalancer</pre>
<ul>
 	<li>Create a route to be able to browse to your app</li>
</ul>
<pre>oc create route edge --service sampleapp-deployment --port 80</pre>
<ul>
 	<li>Retrieve the route that was just created</li>
</ul>
<pre>oc get routes</pre>
<a href="https://msdnshared.blob.core.windows.net/media/2017/12/routes.bmp"><img class="alignnone wp-image-1325" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/routes.bmp" width="875" height="50" /></a>
<ul>
 	<li>browse to "https://your_url/api/values".  Make sure your_url is the url returned from previous step.  In my case, the complete address is https://sampleapp-deployment-sample-project.192.168.99.100.nip.io/api/values</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/12/api.bmp"><img class="alignnone wp-image-1335" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/api.bmp" width="662" height="84" /></a>

&nbsp;
<h1>Setting up Continuous Deployment</h1>
&nbsp;

To deploy the Docker container created by our CI build to the OpenShift Kubernetes cluster, we first need to check-in the deployment config file samplewebapp-oc-deploy.yml we created earlier.  But before we check it in, replace the image tag with a placeholder as shown below that we will replace at deploy time.  Once change is made, check-in the file into your repo.

&nbsp;
<pre>apiVersion: v1
kind: DeploymentConfig
metadata:
  name: sampleapp-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: sampleapp-deployment
    spec:
      containers:
      - image: #{IMAGETAG}#
        name: samplewebapp
        ports: 
        - containerPort: 80 
</pre>
&nbsp;

Create a release in VSTS. Go to <strong>Build and Release</strong> then <strong>Releases</strong>

Click New definition button

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_25.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_25.bmp" width="530" height="194" /></a>

&nbsp;

VSTS will prompt to select a template. Select <strong>Empty </strong>template

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_26.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_26.bmp" width="302" height="446" /></a>

&nbsp;

Name the environment <strong>Development </strong>and click + <strong>Add </strong>in Artifacts tile

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_27.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_27.bmp" width="1189" height="781" /></a>

&nbsp;

&nbsp;

In <strong>Add artifact </strong>blade select <strong>Build </strong>as Source type then select your build as Source (Build definition) and click <strong>Add</strong> button

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_28.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_28.bmp" width="1189" height="781" /></a>

&nbsp;

To enable Continuous Deploy, click on the trigger button and toggle the <strong>Continuous deployment trigger</strong> to <strong>enabled</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_29.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_29.bmp" width="1189" height="781" /></a>

Click on <strong>Tasks </strong> and add the following tasks to go to the tasks for that release definition

Click the + sign to add tasks to the Agent phase

For the first task, we want to replace the <strong>imagetag</strong> place holder with the real image tag.  For that, click <strong>Utility </strong>then add <strong>Replace Tokens </strong>task.  This task can be found in Marketplace in case you don't already have it

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_30.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_30.bmp" width="1189" height="781" /></a>

&nbsp;

&nbsp;

Configure the task as shown below. For <strong>Root directory</strong>, ensure you navigate to where the yml file is located:

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_31.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_31.bmp" width="549" height="523" /></a>
<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_32.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_32.bmp" width="486" height="464" /></a>

&nbsp;

Go to Variables tab and add <strong>IMAGETAG</strong> variable as shown below. Make sure you replace "Your_Repo_Name" with your Docker repository name

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_33.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_33.bmp" width="1189" height="781" /></a>

&nbsp;

Go back to release tasks and add <strong>Command Line</strong> If you can't see the task you can install it from VSTS Marketplace.

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_34.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_34.bmp" width="1189" height="781" /></a>

Configure the task as shown below.   Ensure that your_openshift_url, your_username, your_password are replaced with values from your environment

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_35.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_35.bmp" width="544" height="204" /></a>

&nbsp;

Add another <strong>Command Line</strong> task and enter the following code <strong>oc apply -f samplewebapp-oc-deploy.yml. </strong>Make sure that you set Working folder to where the yml file is located as shown below

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_36.bmp"><img class="alignnone wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_36.bmp" width="602" height="469" /></a>

&nbsp;

Click on <strong>Agent phase </strong>and for Agent queue, select an agent that is running in a machine that has oc utility installed. For information on how to deploy a build and release agent, refer to this <a href="https://docs.microsoft.com/en-us/vsts/build-release/actions/agents/v2-windows">resource</a>

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_38.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_38.bmp" width="1189" height="781" /></a>

&nbsp;

Name your release definition, save and then kick off a release

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_39.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_39.bmp" width="1189" height="781" /></a>

&nbsp;

Make a change to your application. When you commit that change, a continuous integration build will be kicked off

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_40.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_40.bmp" width="1189" height="781" /></a>

&nbsp;

Once the build is done, the build will be released.  Once done, you should see your changes deployed to Openshift Kubernetes cluster

<a href="https://msdnshared.blob.core.windows.net/media/2017/12/oc_41.bmp"><img class="alignnone size-full wp-image-885" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/12/oc_41.bmp" width="1189" height="781" /></a>
I hope this was informative.  Please let me know if one of the steps is unclear or you know a better way of doing anything I described in this blog.  Your feedback will be greatly appreciated.  Happy deploying!!

&nbsp;

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Modernizing a Monolithic Application  using Microservices and Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/thinking-of-going-to-the-cloud-with-your-web-app-here-is-an-example</link>
      <pubDate>Wed, 20 Sep 2017 19:53:43 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=746</guid>
      <description><![CDATA[Context
As companies embark on their digital transformation journeys, pressure on IT organizations...]]></description>
      <content:encoded><![CDATA[<h2>Context</h2>
As companies embark on their digital transformation journeys, pressure on IT organizations have been mounting to levels that have never been experienced before.  Businesses have the following expectations, among others, from their IT organizations:
<ul>
 	<li>Applications need to be developed, deployed and enhanced at a rapid pace</li>
 	<li>Applications are always available, resilient and performant</li>
 	<li>Features expected to match or exceed competitors</li>
 	<li>Applications need to run on different form factors including PCs and mobile</li>
 	<li>All applications delivered must be secure and compliant</li>
</ul>
To meet those expectations, not only do companies need to have the capabilities to build these kind of solutions, but also they have to build them faster than ever before.  This is why many organizations are rethinking how they are architecting and building solutions so that they can better respond to the demands and expectations businesses have on them.  Also, IT organizations are constantly in the lookout for ways to enhance agility, optimize resources consumption and minimize solutions time to market.  One way businesses are achieving those goals is by embracing the cloud.  Trends show that organizations from all sizes either have moved toward scaling down their on-prem data centers in favor of the cloud or contemplating the adoption of the cloud.

A common concern most organizations have while contemplating the adoption of the cloud is how to approach their legacy apps.  When thinking about moving a legacy application to the cloud, a decision has to be made whether the application should be moved as is, a strategy called “lift-and-shift” or it has to be redesigned and transformed to become cloud native.  Furthermore, organizations that choose to transform their applications often undertake the effort to modernize the application architectures as well as embrace a DevOps mindset to enhance agility, reliability and productivity.

Recently I went through an effort to modernize a monolithic n-tier eCommerce application.  At a high level, the application architecture is depicted below:

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/old-arch.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/old-arch.bmp" alt="" class="alignnone size-full wp-image-796" width="1137" height="536" /></a>

This effort included moving the application to the cloud as well as redesigning it to follow a Microservices architecture.  Also, part of this effort was to modernize the application components and take advantage of Azure PaaS offerings whenever applicable.  The final design we decided upon is depicted below.

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/new0-arch.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/new0-arch.bmp" alt="" class="alignnone size-full wp-image-786" width="1384" height="804" /></a>

­­­

In this blog I will go through each application layer, describe aspects that need to be considered to properly implement it and offer a solution to address it using Azure.

&nbsp;
<h2><a></a>External Facing Components</h2>
<h3>Web Portal</h3>
This component is the entry point to the system.  Because this component is external facing, the following aspects have to be considered to implement this capability
<ul>
 	<li><strong>Availability</strong>: users should be able to access the system at any time. The system should also be resilient to handle application as well as infrastructure failures.  Also, there should not be any single point of failure in the system.  If a component in the system fails, the system should continue to respond to requests that are targeting other components in the system</li>
 	<li><strong>Scalability</strong>: as the user base grows, the system should continue to honor its SLAs.</li>
 	<li><strong>Security</strong>: only authorized users should be allowed to login and access the system. Also data can only be accessed by users that have the proper permissions to view and manipulate it.</li>
 	<li><strong>Maintainability</strong>: because this component is the entry point to the system it is paramount that mechanisms be put in place to enable easy deploys and near-zero downtime updates</li>
</ul>
The following Azure services can be used to address this aspect of the solution
<ul>
 	<li>Azure web App</li>
 	<li>Traffic Manager</li>
 	<li>Azure Service Fabric</li>
 	<li>Azure Container Service</li>
 	<li>Azure Active Directory (for authentication and authorization)</li>
 	<li>Content Delivery Network (CDN)</li>
</ul>
<h3><a></a>Authentication and Authorization</h3>
<strong>Azure Active Directory B2C</strong> is a consumer identity and access management in the cloud that is highly available, and that scales to hundreds of millions of identities. It can be easily integrated across mobile and web platforms. Users can log on to all your applications through fully customizable experiences by using their existing social accounts or by creating new credentials.

Furthermore, Azure AD B2C addresses all the capabilities listed above and more.  The following are some of its capabilities:
<ul>
 	<li>Multi-factor Authentication</li>
 	<li>Self-service Password Management</li>
 	<li>Role Based Access Control</li>
 	<li>Application Usage Monitoring</li>
 	<li>Rich auditing and Security Monitoring and Alerting</li>
</ul>
<h3><a></a>Content Delivery Network (CDN)</h3>
Content Delivery Network (CDN) is a group of distributed systems used to improve websites performance by serving website content (i.e. images, scripts, videos, …etc.) from locations that are geographically closest to where requests are made.  If users are expected to be geographically dispersed, a CDN must be used to enhance the responsiveness of the site and improve site usability.  Furthermore, the use of a CDN reduces traffic sent to the origin since a subset of the requests will be handled by the CDN edge servers.

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/CDN.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/CDN.bmp" alt="" class="alignnone size-full wp-image-765" width="1033" height="428" /></a>

Source: https://docs.microsoft.com/en-us/azure/architecture/best-practices/cdn

Azure CDN can be used for this component. It offers a global solution for delivering high-bandwidth content that is hosted in Azure or any other location. The Azure CDN cache can be held at strategic locations to provide maximum bandwidth for delivering content to users.
<h3><a></a>Service Gateway</h3>
Azure API Management is a turnkey solution to publish APIs to external, partner and internal developers to enhance agility, efficiency and usability.  It accomplishes that by offering the following capabilities:
<ul>
 	<li>Expose all APIs behind a single static IP and domain</li>
 	<li>Get near real-time usage, performance and health analytics</li>
 	<li>Automate management and integrate using REST API, PowerShell, and Git</li>
 	<li>Provision API Management and scale it on demand in one or more geographical regions</li>
 	<li>Self-service API key management</li>
 	<li>Auto-generated API catalog, documentation, and code samples</li>
 	<li>OAuth-enabled API console for exploring APIs without writing code</li>
 	<li>Sign in using popular Internet identity providers and Azure Active Directory</li>
 	<li>Client certificate authentication</li>
 	<li>Simplify and optimize requests and responses with transformation policies</li>
 	<li>Secure APIs with key, JSON Web Token (JWT) validation, and IP filtering</li>
 	<li>Protect your APIs from overload and overuse with quotas and rate limits</li>
 	<li>Use response caching for improved latency and scale</li>
</ul>
&nbsp;
<h2><a></a>Internal Facing Components</h2>
<h3><a></a>Domain Services</h3>
The recommended implementation option for this layer is REST based APIs that expose services to perform a well-defined function (Bounded Context) in the system.  The services need to have their own data layer that should not be shared with other services except through well-designed API calls.  Services need to be independent from one another.

When dealing with a system that could encompass a large number of components running on a cluster of machines, management of such infrastructure can be a daunting task.  There are a number of orchestrators that try to make this task more manageable.  Both Service Fabric and Azure Container Service provide container orchestration capabilities.  However, there are key differences between these two services:
<h4><a></a><strong>Service Fabric</strong></h4>
The following diagram shows Microservices using Service Fabric as a deployment target:

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/Service-Fabric.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/Service-Fabric.bmp" alt="" class="alignnone size-full wp-image-776" width="1069" height="515" /></a>

Source: <a href="https://docs.microsoft.com/en-us/azure/architecture/guide/architecture-styles/microservices">https://docs.microsoft.com/en-us/azure/architecture/guide/architecture-styles/microservices</a>
<h4><a></a><strong>Azure Container Service</strong></h4>
As mentioned earlier, ACS supports three of the most popular orchestrators, namely Kubernetes, DC/OS and Swarm.   The following is a depiction of ACS as a deployment target for the system:

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/ACS.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/ACS.bmp" alt="" class="alignnone size-full wp-image-756" width="1037" height="493" /></a>

Source: <a href="https://docs.microsoft.com/en-us/azure/architecture/guide/architecture-styles/microservices">https://docs.microsoft.com/en-us/azure/architecture/guide/architecture-styles/microservices</a>
<h3><a></a>Batch Processes</h3>
A number of Azure Services can be leveraged to handle any kind of background processing.  The following is a list of these services with a brief description:
<ul>
 	<li><strong>Azure Batch</strong>: a platform service for running large-scale parallel and high-performance computing (HPC) applications efficiently in the cloud. Azure Batch schedules compute-intensive work to run on a managed collection of virtual machines, and can automatically scale compute resources to meet the needs of your jobs.</li>
 	<li><strong>Azure Functions</strong>: a Serverless technology that allows to run small pieces of code, in the cloud without worrying about a whole application or the infrastructure to run it.</li>
 	<li><strong>Logic App</strong>: provides a way to simplify and implement scalable integrations and workflows in the cloud. It provides a visual designer to model and automate your process as a series of steps known as a workflow.</li>
</ul>
<h3><a></a>Data Persistence Layer</h3>
For data persistence, two technologies are dominating the database landscape, namely NoSQL and relational databases.  NoSQL databases have gained popularity because they are easier to scale, allows for faster development, and allows to store unstructured data.

Azure Cosmos DB is a globally distributed database service designed to enable you to elastically and independently scale throughput and storage across any number of geographical regions with a comprehensive SLA. You can develop document, key/value, or graph databases with Cosmos DB using a series of popular APIs and programming models.

For scenarios where data consistency and ACID (Atomicity, Consistency, Isolation, Durability) compliance is important, Azure SQL Database is a high-performance, reliable, and secure relational database-as-a service that can be leveraged without needing to manage infrastructure.
<h3>Reporting</h3>
Azure offers many services that can be leveraged for reporting.  Azure SQL Data Warehouse can be used to load and aggregate data from various data sources to perform analysis and reporting.  It is a massively parallel processing (MPP) cloud-based, scale-out, relational database capable of processing massive volumes of data.

To help visualize BI reports, <strong>Power BI Embedded</strong> can be leveraged to integrate Power BI reports into your web or mobile applications.  Power BI Embedded is an Azure service that enables app developers to surface Power BI data experiences within their applications.

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/PowerBI.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/PowerBI.bmp" alt="" class="alignnone size-full wp-image-766" width="1098" height="476" /></a>

Source: <a href="https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-what-is-power-bi-embedded">https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-what-is-power-bi-embedded</a>

<strong> </strong>

One thing to keep in mind is the approach I described above is not the only approach that fits the scenario at hand.  There could be other ways to achieve this goal that are valid as well.

I hope this blog was helpful to those who are learning about Azure and those of you who are considering to move some of their workloads to the cloud.  Note that you can get started to explore Azure for free.  Let me know your thoughts about what has been discussed in this bog and please let me know how I can improve by leaving your feedback.]]></content:encoded>
    </item>
    <item>
      <title>Setting up CI/CD for Docker Container Running in Kubernetes using VSTS</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/setting-up-cicd-for-docker-container-running-in-kubernetes-using-vsts</link>
      <pubDate>Mon, 29 May 2017 15:02:42 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=625</guid>
      <description><![CDATA[Context
&nbsp;

In my last post, I covered how you can create a simple Web API, run the Web API...]]></description>
      <content:encoded><![CDATA[<h2>Context</h2>
&nbsp;

In my last post, I covered how you can create a simple Web API, run the Web API in a Docker container and then deploy the container to a Kubernetes cluster provisioned using Azure Container Service (ACS) in Azure.  You can find the full post <a href="https://blogs.msdn.microsoft.com/najib/2017/05/27/web-api-with-docker-and-kubernetes/">here</a>.

In this blog, I will cover how CI/CD can be implemented so that the sample Web API can be deployed automatically as soon as a change is made to the Web API code.  To create the Web API code with Docker support, follow the section “Creating a simple web API with Docker Support using Visual Studio” in my last post <a href="https://blogs.msdn.microsoft.com/najib/2017/05/27/web-api-with-docker-and-kubernetes/">here</a>.  This blog assumes you have a VSTS account setup and a Team Project created.  You can create a VSTS account for free <a href="https://go.microsoft.com/fwlink/?LinkId=307137&amp;clcid=0x409&amp;wt.mc_id=o~msft~vscom~product-vsts-nav~menu&amp;campaign=o~msft~vscom~product-vsts-nav~menu">here</a>.  It also assumes that the sample API code is checked in to the Team Project version control.

&nbsp;
<h2>Pre-requisites</h2>
&nbsp;

Some tasks we will be using to set up CI/CD don’t come out of the box with VSTS.  Instead, you will need to install them from the VSTS Marketplace.  The following extensions need to be installed:
<ul>
 	<li>Docker Integration</li>
 	<li>Kubernetes extension</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/1cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/1cicd.bmp" alt="" class="alignnone size-full wp-image-705" height="461" width="953" /></a>
<h2></h2>
<h2>Setting up Continuous Integration</h2>
&nbsp;
<ul>
 	<li>Login to the Team Project in VSTS where the code is checked-in</li>
 	<li>Tap <strong>Build and Release </strong>tab and then click on <strong>Builds </strong></li>
 	<li>Click <strong>New definition</strong> button</li>
 	<li>Click on <strong>empty process </strong>link</li>
 	<li>Add <strong>Docker Compose</strong> task from the Docker integration extension installed from Marketplace. Set <strong>Docker Compose File</strong> field to <strong>docker-compose.ci.build.yml.  </strong>Set Command field to <strong>up</strong></li>
</ul>
<strong> <a href="https://msdnshared.blob.core.windows.net/media/2017/05/2cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/2cicd.bmp" alt="" class="alignnone size-full wp-image-715" height="951" width="1635" /></a></strong>

&nbsp;
<ul>
 	<li>Add another <strong>Docker Compose</strong> task from the Docker integration extension installed. Set <strong>Docker Compose File</strong> field to <strong>docker-compose.yml.  </strong>Set Command field to <strong>build</strong></li>
</ul>
<strong> <a href="https://msdnshared.blob.core.windows.net/media/2017/05/3cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/3cicd.bmp" alt="" class="alignnone size-full wp-image-725" height="977" width="1522" /></a></strong>
<ul>
 	<li>Add <strong>Docker</strong> step from the Docker integration extension. For Docker Registry Connection field, click the plus sign (+) and you will be prompted to enter your Docker registry credentials.  VSTS uses those credentials to push the generated Docker image.  Set Action field to<strong> Push an image.   </strong>Set image name to xyz/sampleapi:latest.  Make sure you replace “xyz” with your actual Docker repo name</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/4cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/4cicd.bmp" alt="" class="alignnone size-full wp-image-645" height="705" width="1430" /></a>
<ul>
 	<li>Add <strong>Copy and Publish Build Artifacts </strong>task and configure it as shown below</li>
 	<li>Save and queue a build by clicking the<strong> Save &amp; queue</strong> button. For the Agent queue field, select <strong>Hosted Linux</strong> <strong>Preview</strong> option</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/6cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/6cicd.bmp" alt="" class="alignnone size-full wp-image-665" height="606" width="1003" /></a>
<ul>
 	<li>Click <strong>Queue</strong> and the build should be queued and executed once an agent is available</li>
</ul>
&nbsp;
<h2>Setting up Continuous Deployment</h2>
&nbsp;

Now that we have a build setup, we can set up a release that can deploy the application to our Kubernetes cluster.  The following are the steps to do so
<ul>
 	<li>Create a deploy file called <strong>yml</strong> with the content below and check it in to the repository:</li>
</ul>
<pre>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: sampleapi-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: sampleapi
    spec:
      containers:
      - name: sampleapi
        image: xyz/sampleapi:latest
        ports:
        - containerPort: 80

</pre>
&nbsp;

&nbsp;
<ul>
 	<li>Download <strong>kubectl from </strong><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">here</a><strong> and check it in to the repository</strong></li>
 	<li>Tab on <strong>Build &amp; Release</strong> and click <strong>Releases</strong></li>
 	<li>Click on <strong>New Definition</strong></li>
 	<li>Select <strong>Empty</strong> as the release template and click <strong>Next</strong></li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/7cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/7cicd.bmp" alt="" class="alignnone size-full wp-image-675" height="851" width="707" /></a>
<ul>
 	<li>Check <strong>Continuous Deployment</strong> option</li>
 	<li>Click on <strong>Add Tasks</strong></li>
 	<li>Select <strong>Kubernetes Apply Task. </strong>Click on <strong>Add </strong>next to <strong>k8s end point</strong> field and fill out the information for your Kubernetes cluster with information similar to below</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/8cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/8cicd.bmp" alt="" class="alignnone size-full wp-image-685" height="514" width="843" /></a>
<ul>
 	<li>For Kubeconfig field, set it to the content from the config file inside .kube directory generated when the <strong>az acs kubernetes get-credentials </strong>is run as show in the previous <a href="https://blogs.msdn.microsoft.com/najib/2017/05/27/web-api-with-docker-and-kubernetes/">post</a></li>
</ul>
<ul>
 	<li>Click <strong>OK</strong> to return to the task</li>
 	<li>Set the <strong>YAML file</strong> and <strong>kubectl</strong> binary as shown below</li>
</ul>
&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/9cicd.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/9cicd.bmp" alt="" class="alignnone size-full wp-image-695" height="474" width="1382" /></a>

&nbsp;
<ul>
 	<li>Click on <strong>Run on agent</strong> and make sure you select <strong>Hosted Linux Preview</strong></li>
 	<li>Click save icon and queue a release and this should conclude setting up Continuous Deployment.</li>
</ul>
&nbsp;

<strong>Note</strong>:  if you make a change to the code, the image version number will need to be updated so that Kubernetes can trigger a deployment.  One way to do this is to include a placeholder in the <strong>sampleapi.yml</strong> as well <strong>docker-compose.yml</strong> files and then replace these placeholders with actual version numbers for each build during build time.  A task such as <strong>Replace Tokens </strong>can be used to accomplish this substitution.

&nbsp;

We have just walked through how to setup CI/CD for a Web API with Docker support running on a Kubernetes cluster.  I hope this was informative.

&nbsp;

Please leave us your feedback.]]></content:encoded>
    </item>
    <item>
      <title>Running Web API using Docker and Kubernetes</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/web-api-with-docker-and-kubernetes</link>
      <pubDate>Sat, 27 May 2017 17:08:11 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=545</guid>
      <description><![CDATA[Context
As companies are continuously seeking ways to become more Agile and embracing DevOps...]]></description>
      <content:encoded><![CDATA[<h2>Context</h2>
As companies are continuously seeking ways to become more Agile and embracing DevOps culture and practices, new designs principles have emerged that are more closely aligned with those aspirations.  One such a design principle that had gained more popularity and adoption lately is Microservices.  By decomposing applications to smaller independent components, companies are able to achieve the following benefits:
<ul>
 	<li>Ability to scale specific components of the system. If “Feature1” is experiencing an unexpected rise in traffic, that component could be scaled without the need to scale the other components which enhances efficiency of infrastructure use</li>
 	<li>Improves fault isolation/resiliency: System can remain functional despite the failure of certain modules</li>
 	<li>Easy to maintain: teams can work on system components independent of one another which enhances agility and accelerates value delivery</li>
 	<li>Flexibility to use different technology stack for each component if desired</li>
 	<li>Allows for container based deployment which optimizes components’ use of computing resources and streamlines deployment process</li>
</ul>
I wrote a detailed blog on the topic of Microservices <a href="https://blogs.msdn.microsoft.com/najib/2017/01/03/what-are-microservices-and-why-should-you-care/">here</a>

In this blog, I will focus more on the last bullet.  We will see how easy it is to get started with Containers and have them a deploy mechanism of our Microservices.  I will also cover the challenge that teams might face when dealing with a large number of Microservices and Containers and how to overcome that challenge
<h2>Creating a simple web API with Docker Support using Visual Studio</h2>
For this section, I am using Visual Studio 2017 Enterprise Edition to create the Web API.
<ul>
 	<li>In Visual Studio, go to File =&gt; New =&gt; Project =&gt; Web =&gt; ASP.NET Core Web Application (.NET Core)</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/1k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/1k8s.bmp" alt="" class="alignnone size-full wp-image-555" height="988" width="1283" /></a>
<ul>
 	<li>Select <strong>Web API </strong>and make sure that <strong>Enable Docker Support </strong>is enabled and then click <strong>OK </strong>to generate the code for the web API</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/2k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/2k8s.bmp" alt="" class="alignnone size-full wp-image-565" height="768" width="1166" /></a>

<strong>Note that the code generated by Visual Studio has the files needed by Docker to compile and run the generated application</strong>
<ul>
 	<li>Open <strong>docker-compose.yml</strong> file and prefix the image name with your docker repository name. For example, if your Docker repository name is xyz then the entry in the <strong>docker-compose.yml </strong>should be:  <strong>image:</strong> <strong>xyz/sampleapi  </strong>Here is how that file should look like:</li>
</ul>
&nbsp;
<pre>version: '1'
services:
  sampleapi:
    image: xyz/sampleapi
    build:
      context: ./SampleAPI
      dockerfile: Dockerfile
</pre>
&nbsp;

&nbsp;
<ul>
 	<li>Check in the generated Web API code into Version Control System. You can use the git repository within Visual Studio Team Services for free <a href="https://go.microsoft.com/fwlink/?LinkId=307137&amp;clcid=0x409&amp;wt.mc_id=o~msft~vscom~home-vsts-hero~27308&amp;campaign=o~msft~vscom~home-vsts-hero~27308">here</a></li>
 	<li>Checkout the code to an Ubuntu machine with Docker engine installed. In Azure you can provision an Ubuntu machine with Docker using “Docker on Ubuntu Server” as shown below</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/3k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/3k8s.bmp" alt="" class="alignnone size-full wp-image-575" height="328" width="1193" /></a>
<ul>
 	<li>Run the code by navigating to the directory where the repository was cloned and then run the following command</li>
</ul>
<strong>          docker-compose -f docker-compose.ci.build.yml up &amp;&amp; docker-compose up</strong>
<ul>
 	<li>Verify that the container is running by entering this command</li>
</ul>
<strong>          docker ps</strong>
<ul>
 	<li>This should return the container that was just created in the previous step. The output should look something similar to below</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/4k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/4k8s.bmp" alt="" class="alignnone size-full wp-image-585" height="203" width="1107" /></a>
<ul>
 	<li>Finally push the docker image created (i.e. xyz/sampleapi) to the Docker image Registry</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/5k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/5k8s.bmp" alt="" class="alignnone size-full wp-image-595" height="318" width="1238" /></a>

<strong>docker push  xyz/sampleapi:latest</strong>

As your application becomes more popular and users ask for more features, new microservices will need to be created.  As the number of microservices increases, so is the complexity of deploying, monitoring, scaling and managing the communication among them.  Luckily there are orchestration tools available that make this task more manageable.

&nbsp;
<h2>Orchestrating Microservices</h2>
Managing a large number of Microservices can be a daunting task.  Not only will you need to to track their health, you will also need to ensure that they are scaled properly, deployed without interrupting users and also recover when there are failures.  The following are orchestrators that have been created to meet this need:
<ul>
 	<li>Service Fabric</li>
 	<li>Docker Swarm</li>
 	<li>DC/OS</li>
 	<li>Kubernetes</li>
</ul>
Stacking up these tools against one another is out of scope for this blog.  Instead, I will focus more on how we can deploy the Web API we created earlier into Kubernetes using Azure Container Service.
<h2>Creating Kubernetes in Azure Container Service (ACS)</h2>
For this section, I am using a Windows Server 2016 machine.  You can use any platform to achieve this but you might need to make a few minor changes to the steps detailed below
<ul>
 	<li>Install Azure CLI using this <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli">link</a></li>
 	<li>Login to Azure using Azure CLI by entering the following command</li>
</ul>
<strong>           az login</strong>
<ul>
 	<li>Follow the steps to login to Azure using Azure CLI. Also if you have access to multiple subscriptions, make sure the right subscription is selected</li>
</ul>
<strong>          az account set  --subscription “your subscription ID”</strong>

&nbsp;
<ul>
 	<li>Create a resource group</li>
</ul>
<strong>          az group create -l eastus -n webAPIK8s</strong>

<strong> </strong>
<ul>
 	<li>Create Kubernetes cluster in ACS under the resource group created</li>
</ul>
<strong>          az acs create -n myKubeCluster -d myKube -g webAPIK8s  --generate-ssh-keys --orchestrator-type kubernetes --agent-count 1 --agent-vm-size Standard_D1</strong>
<ul>
 	<li>Download the Kubernetes client by entering this command:</li>
</ul>
<strong>          az acs kubernetes install-cli --install-location=C:\kubectl\kubectl.exe</strong>

<strong>Note:</strong> Ensure that <strong>kubectl </strong>folder exists otherwise the command would throw an error
<ul>
 	<li>Get the Kubernetes cluster credentials</li>
</ul>
<strong>          az acs kubernetes get-credentials --resource-group=webAPIK8s  --name=myKubeCluster</strong>
<ul>
 	<li>Tunnel into the Kubernetes cluster</li>
</ul>
<strong>          C:\kubectl\kubectl.exe proxy</strong>

&nbsp;
<ul>
 	<li>Open a web browser and navigate to <strong>https://localhost:8001/ui</strong></li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2017/05/6k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/6k8s.bmp" alt="" class="alignnone size-full wp-image-605" height="1061" width="1928" /></a>

&nbsp;
<h2>Deploying the Web API</h2>
To deploy to the Kubernetes cluster, a deployment descriptor is needed.  Create a file called <strong>sampleapi.yml </strong>in the machine you have used to connect to the Kubernetes cluster and fill it with the following:
<pre>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: sampleapi-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: sampleapi
    spec:
      containers:
      - name: sampleapi
        image: xyz/sampleapi:latest
        ports:
        - containerPort: 80

</pre>
<ul>
 	<li>Deploy the app by opening a command line, navigating to where the yml file is located and running</li>
</ul>
<strong>          C:\kubectl\kubectl.exe apply -f sampleapi.yml</strong>

<strong> </strong>
<ul>
 	<li>To expose the API outside of the cluster, run the following command</li>
</ul>
<strong>          C:\kubectl\kubectl.exe expose deployments </strong><strong>sampleapi-deployment --port=80 --type=LoadBalancer</strong>

<strong> </strong>
<ul>
 	<li>Periodically check whether the service is exposed. Keep running this command until the service gets an External-IP</li>
</ul>
<strong>         C:\kubectl\kubectl.exe get services</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/7k8s.bmp"><img src="https://msdnshared.blob.core.windows.net/media/2017/05/7k8s.bmp" alt="" class="alignnone size-full wp-image-615" height="275" width="744" /></a>
<ul>
 	<li>Once the service is exposed, obtain its external IP (i.e. xxx.xxx.xxx.xxx) and check whether you can access the api by using either Rest client (i.e. Postman) or simply opening a web browser and entering:</li>
</ul>
<strong>          https://xxx.xxx.xxx.xxx/api/values </strong>
<h2>Conclusion</h2>
Working with a large number of Microservices can be a challenging task.  Also creating an orchestrator cluster of any type can sometimes be hard.  With Azure Container Service (ACS), creating a cluster can be as easy as entering one command.  Also Visual Studio can be used to jump start a project that has Docker support.  I hope this blog was informative.   My next blog will cover how CI/CD can be implemented with this scenario.

Please leave your feedback…

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>What are Microservices and Why Should You Care?</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/what-are-microservices-and-why-should-you-care</link>
      <pubDate>Tue, 03 Jan 2017 17:19:41 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=496</guid>
      <description><![CDATA[Context

Nowadays, trends show that market conditions are changing constantly and at a pace we...]]></description>
      <content:encoded><![CDATA[<strong><u>Context</u></strong>

Nowadays, trends show that market conditions are changing constantly and at a pace we have never seen before.   New companies come into mature industries and completely disrupt them while existing companies that have been around for a long time are struggling to survive and to hold on to their market share.

Also, building highly available and resilient software has become an essential competency no matter what business you are in.  Nowadays, all companies are becoming software companies.  Let’s take for example companies in the retail industry. Before, most companies in this industry competed on who can make products available on the shelves with the lowest possible price.  Now companies pursue more advanced and sophisticated techniques to lure customers.  Nowadays, it’s all about predicting customers’ behaviors by deeply understanding customers’ sentiments, brand engagements and history of their searches and purchases.  There is no doubt that companies who are harnessing these capabilities are more successful and profitable than those that do not.

To win in such market conditions, not only do companies have to have the capabilities to build these kind of solutions, but also they have to build them faster than their competitors.  This is why many organizations are rethinking how they are architecting and building solutions so that they can better embrace changes in customers’ and market’s demands.  Also, the rise of cloud computing has made organizations embrace design approaches that allow pieces of solutions to be scaled independently to optimize infrastructure resources consumption.

&nbsp;

<strong><u>Software Architecture Evolution</u></strong>

Looking at how software designs have evolved over the years, initially applications were mainly monolithic applications targeting desktops.  As internet became more prominent, a new style of applications emerged, namely Client-Server.  In this type of architecture, we ran some code on desktops while another part of the application ran on a remote server somewhere. The server component tended to group both business logic as well as some kind of data persistence mechanism.  As applications grew, there was a need to separate the business logic from the data persistence layer so a new style emerged namely 3-tier in which presentation layer, business logic and data persistence all lived on separate layers.  The separation of layers have grown beyond the 3-layers giving birth to the concept of the n-tier architectures in which teams can create flexible and reusable components.  The figure below shows a depiction of this type of architecture

<a href="https://msdnshared.blob.core.windows.net/media/2017/01/n-tier-logical.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/01/n-tier-logical-300x135.png" alt="" class="alignnone size-medium wp-image-735" height="135" width="300" /></a>

Although the architecture above divides the solution into multiple layers, multiple flaws can be pointed out:
<ul>
 	<li>The monolithic nature of the solution makes scaling the app not resource efficient</li>
 	<li>Code base for the app tends to be large which makes it harder to change and maintain</li>
 	<li>Collaborating on monolithic apps is challenging since multiple teams could be making changes to the code simultaneously which increases the likelihood of merge conflicts</li>
 	<li>A fatal error in one of the components could bring the entire solution down</li>
 	<li>Teams are bound to a specific technology stack for the entire solution</li>
</ul>
Because of the limitation mentioned above, a new design approach named Microservices has gained popularity in the last few years.

&nbsp;

<strong><u>Microservices Overview</u></strong>

Microservices is an approach to application architecture in which an application is composed of small, independent and flexible components, each focusing on solving a single domain within the application.     The figure below shows a depiction of such an approach

<a href="https://msdnshared.blob.core.windows.net/media/2017/01/microservices-logical.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/01/microservices-logical-300x159.png" alt="" class="alignnone size-medium wp-image-737" height="159" width="300" /></a>

&nbsp;

This approach solves a number of limitations imposed by monolithic applications. Some of the benefits you would get by adopting this approach include:
<ul>
 	<li>Ability to deploy subset of the system. If a customer is not interested in one of the modules, they can choose not to deploy that module</li>
 	<li>Ability to scale specific components of the system. If “Feature1” is experiencing an unexpected rise in traffic, that component could be scaled without the need to scale the other components which enhances efficiency of infrastructure use</li>
 	<li>Improves fault isolation/resiliency: System can remain functional despite the failure of certain modules</li>
 	<li>Easy to maintain: teams can work on system components independent of one another which enhances agility and accelerates value delivery</li>
 	<li>Flexibility to use different technology stack for each component if desired</li>
 	<li>Enhances the ability of developers to gain domain knowledge for a specific area</li>
 	<li>Allows for container based deployment which optimizes components’ use of computing resources and streamlines deployment process</li>
</ul>
&nbsp;

In my next post I will drill deeper into the last point which is a suitable deployment strategy for such an architecture.  Stay tuned…<strong><u>   </u></strong>

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Versioning and Deploying Salesforce Metadata using TFS/VSTS</title>
      <link>https://docs.microsoft.com/archive/blogs/najib/versioning-and-deploying-salesforce-metadata-using-tfsvsts</link>
      <pubDate>Thu, 16 Jun 2016 10:26:23 GMT</pubDate>
      <dc:creator><![CDATA[Najib Z]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/najib/?p=45</guid>
      <description><![CDATA[In this blog, I will show how you can use Visual Studio Team Services (VSTS) version control system...]]></description>
      <content:encoded><![CDATA[In this blog, I will show how you can use Visual Studio Team Services (VSTS) version control system to version control Salesforce.com Metadata.  I will also show how the Build feature in VSTS can enable you to deploy Salesforce Metadata from one Salesforce development instance to a Salesforce QA instance.  Finally, we will configure Continuous Integration (CI) so that each time you commit and push a change to a VSTS git repository, a build is triggered, which deploys to the Salesforce QA instance giving you immediate feedback on whether your changes broke anything in the Salesforce QA instance.

This walkthrough assumes some familiarity with Salesforce.com programming as well as git based version control system.  Also, we will use VSTS but most steps apply to TFS as well.  Note that you can get a VSTS account for free at https://www.visualstudio.com/products/visual-studio-team-services-vs

Before we start make sure your system has the following:
<ul>
 	<li>Eclipse IDE (https://www.eclipse.org/downloads/)</li>
 	<li>Force.com IDE Plugin (<a href="https://developer.salesforce.com/page/Force.com_IDE_Installation">https://developer.salesforce.com/page/Force.com_IDE_Installation</a>)</li>
 	<li>Java SE Development Kit (JDK), Runtime Environment 7, or later (https://www.oracle.com/technetwork/java/javase/downloads/index.html)</li>
 	<li>VSTS (or TFS) Account (https://www.visualstudio.com/products/visual-studio-team-services-vs)</li>
 	<li>Salesforce account (https://www.salesforce.com/form/signup/freetrial-sales.jsp)</li>
 	<li>Team Explorer Everywhere plugin (<a href="https://marketplace.eclipse.org/content/team-explorer-everywhere">https://marketplace.eclipse.org/content/team-explorer-everywhere</a>)</li>
</ul>
&nbsp;

In this document we will go over the following:
<ol>
 	<li>Create a Team Project in VSTS called MySalesforceApp</li>
 	<li>Connect to MySalesforceApp from Eclipse IDE and clone the repository</li>
 	<li>Create a Force.com project, connect it to the Salesforce development instance and retrieve its metadata</li>
 	<li>Store the retrieved metadata in VSTS git version control system</li>
 	<li>Set up a Continuous Integration build and deploy to the Salesforce QA instance</li>
 	<li>Verify the CI behaves as expected</li>
</ol>
&nbsp;

<strong><u>Create a Team Project in VSTS called MySalesforceApp</u></strong>

Login to your VSTS account if you already have one.  If not, create one <a href="https://www.visualstudio.com/products/visual-studio-team-services-vs">here</a>.  Once signed up, you can create a new Team Project by clicking “New”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/test.bmp"><img class="alignnone wp-image-75" src="https://msdnshared.blob.core.windows.net/media/2016/06/test.bmp" alt="test" width="745" height="442" /></a>

&nbsp;

Enter the Team Project name, select a Process Template and version control as shown below and then click “Create Project”

<img class="alignnone wp-image-245" src="https://msdnshared.blob.core.windows.net/media/2016/06/2_TP_create_dialog.bmp" alt="2_TP_create_dialog" width="614" height="548" /><u></u>

&nbsp;

<strong><u>Connect to MySalesforceApp from Eclipse IDE and clone the repository</u></strong>

In Eclipse, change Perspective to  ‘’Team Foundation Server Exploring”.  If you don’t see that perspective, get this plugin

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/3_TFS_Perspective.bmp"><img class="alignnone size-full wp-image-235" src="https://msdnshared.blob.core.windows.net/media/2016/06/3_TFS_Perspective.bmp" alt="3_TFS_Perspective" width="386" height="517" /></a>

&nbsp;

Within Eclipse’s Team Explorer,  go to “Home” -&gt; “Projects” -&gt; “Connect to Team Projects…”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/4_Eclipse-project.bmp"><img class="alignnone wp-image-225" src="https://msdnshared.blob.core.windows.net/media/2016/06/4_Eclipse-project.bmp" alt="4_Eclipse project" width="831" height="249" /></a>

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/5_Eclipse_Project.bmp"><img class="alignnone wp-image-195" src="https://msdnshared.blob.core.windows.net/media/2016/06/5_Eclipse_Project.bmp" alt="5_Eclipse_Project" width="537" height="386" /></a>

&nbsp;

Click “Servers” and add your VSTS url and then click “OK”

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/6_Project_eclipse.bmp"><img class="alignnone wp-image-205" src="https://msdnshared.blob.core.windows.net/media/2016/06/6_Project_eclipse.bmp" alt="6_Project_eclipse" width="564" height="339" /></a>

&nbsp;

Once server is added, you can click next.  You will be presented with a login page.  Enter your username and password.  Once authenticated, you will be presented with list of team projects.

Select the “MySalesforceApp” Team Project and then click “Finish”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/7_Eclpise_Project.bmp"><img class="alignnone wp-image-215" src="https://msdnshared.blob.core.windows.net/media/2016/06/7_Eclpise_Project.bmp" alt="7_Eclpise_Project" width="604" height="300" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/8_eclipse_project.bmp"><img class="alignnone wp-image-185" src="https://msdnshared.blob.core.windows.net/media/2016/06/8_eclipse_project.bmp" alt="8_eclipse_project" width="837" height="389" /></a>

&nbsp;

In “Team Explorer “, click on “Git Repositories”, then right click on “MySalesforceApp” and click “Import Repository”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/9_repos.bmp"><img class="alignnone wp-image-176" src="https://msdnshared.blob.core.windows.net/media/2016/06/9_repos.bmp" alt="9_repos" width="381" height="352" /></a>

&nbsp;

Select “MySalesforceApp” repository and click “Next”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/10_git_repo.bmp"><img class="alignnone wp-image-166" src="https://msdnshared.blob.core.windows.net/media/2016/06/10_git_repo.bmp" alt="10_git_repo" width="503" height="451" /></a>

&nbsp;

Enter the clone parameters.  Take note of the location in which you are cloning the repository.  Make sure that this location is the same as the Eclipse Workspace location.  You will need to create the Salesforce project in same location

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/11_clone_params.bmp"><img class="alignnone wp-image-156" src="https://msdnshared.blob.core.windows.net/media/2016/06/11_clone_params.bmp" alt="11_clone_params" width="493" height="511" /></a>

&nbsp;

Clicking “Next” would show the summary page.  You can click “Next” and then choose “Create generic Eclipse projects for selected folders”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/12_project_impott.bmp"><img class="alignnone wp-image-155" src="https://msdnshared.blob.core.windows.net/media/2016/06/12_project_impott.bmp" alt="12_project_impott" width="472" height="493" /></a>

&nbsp;

Click “Next” and then “Finish”

&nbsp;

<strong><u>Create a Force.com project, connect it to the Salesforce development instance and retrieve its metadata</u></strong>

Before you create the “Force.com” project, make sure that Eclipse’s Workspace is at the same location as the location where the repository was copied in the previous step

To find the current Workspace location, go to “File” -&gt; “Switch Workspace” -&gt; “Other”.  The workspace should show

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/13_select_workspace.bmp"><img class="alignnone wp-image-146" src="https://msdnshared.blob.core.windows.net/media/2016/06/13_select_workspace.bmp" alt="13_select_workspace" width="592" height="361" /></a>

&nbsp;

Let’s create the Force.com project.  In Eclipse, go to “Force.com” perspective

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/14_Open_persepective.bmp"><img class="alignnone size-full wp-image-145" src="https://msdnshared.blob.core.windows.net/media/2016/06/14_Open_persepective.bmp" alt="14_Open_persepective" width="375" height="506" /></a>

&nbsp;

Go to “File” -&gt; “New” -&gt; “Force.com Project”.

Enter the project info.  For “Project name” enter the same name as VSTS Team Project name (MySalesforceApp).  Also, you will need to enter your Salesforce.com org credentials.  Click “Next” and then click “Finish”.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/15_create_force.bmp"><img class="alignnone wp-image-135" src="https://msdnshared.blob.core.windows.net/media/2016/06/15_create_force.bmp" alt="15_create_force" width="490" height="642" /></a>

&nbsp;

<strong>Note:</strong> in some instances, a Security Token is required.  If you don’t enter one, you would get an error window along with the instructions on how to get a valid Security Token.

At this point, the project structure should look like this:

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/16_eclipse_prjct_structure.bmp"><img class="alignnone wp-image-125" src="https://msdnshared.blob.core.windows.net/media/2016/06/16_eclipse_prjct_structure.bmp" alt="16_eclipse_prjct_structure" width="1413" height="898" /></a>

&nbsp;

&nbsp;

<strong><u>Store the retrieved metadata in VSTS git version control system</u></strong>

To store the code in VSTS git repo, you will need to commit the changes and push the branch to the remote repository in VSTS.  To commit the changes, you can either do so from the command line or from Eclipse by going to “Team Foundation Server Exploring” perspective and clicking “Git Repositories” and right clicking “MySalesforceApp” and selecting “Open”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/17_tfs_exploring.bmp"><img class="alignnone wp-image-115" src="https://msdnshared.blob.core.windows.net/media/2016/06/17_tfs_exploring.bmp" alt="17_tfs_exploring" width="881" height="349" /></a>

Right click on the repo and select “Commit”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/18_commit.bmp"><img class="alignnone wp-image-105" src="https://msdnshared.blob.core.windows.net/media/2016/06/18_commit.bmp" alt="18_commit" width="807" height="449" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/19_initialCommit.bmp"><img class="alignnone wp-image-95" src="https://msdnshared.blob.core.windows.net/media/2016/06/19_initialCommit.bmp" alt="19_initialCommit" width="707" height="592" /></a>

&nbsp;

Check all the files and then click “Commit and Push”.  This would add the project to the remote repository.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/20_pushBranch.bmp"><img class="alignnone wp-image-85" src="https://msdnshared.blob.core.windows.net/media/2016/06/20_pushBranch.bmp" alt="20_pushBranch" width="639" height="479" /></a>

&nbsp;

Click “Next” and then “Finish”.  At this point you should have the code pushed to the repository in VSTS.  To check that, login to VSTS and then go to the “Code” hub; there you can see the project we just pushed.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/21_vsts_repo.bmp"><img class="alignnone wp-image-445" src="https://msdnshared.blob.core.windows.net/media/2016/06/21_vsts_repo.bmp" alt="21_vsts_repo" width="1108" height="406" /></a>

&nbsp;

&nbsp;

&nbsp;

<strong><u>Setup Continuous Integration build</u></strong>

Get the Force.com Migration Tool from Salesforce.  Login to Salesforce.com -&gt; Setup -&gt; Build -&gt; Develop -&gt; Tools.  This page contains a number of tools made available by Salesforce.com.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/22_sf_tools.bmp"><img class="alignnone wp-image-435" src="https://msdnshared.blob.core.windows.net/media/2016/06/22_sf_tools.bmp" alt="22_sf_tools" width="850" height="286" /></a>

&nbsp;

The tool we are interested in is “Force.com Migration Tool”.  Click on the link and the tool would download.  Once downloaded, unzip the file and copy “ant-salesforce.jar” file.

Create a folder called “deploy” inside the force.com project and paste the “ant-salesforce.jar” file into the “deploy” folder

Create “build.xml” file inside the “deploy“ folder and paste the following:
<pre>&lt;project name="Sample usage of Salesforce Ant tasks" default="deployCodeAndRunTests" basedir="." xmlns:sf="antlib:com.salesforce"&gt;

    &lt;property file="build.properties"/&gt;
    &lt;property environment="env"/&gt;

    &lt;!-- Setting default value for username, password and session id properties to empty string 
         so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
         will be treated literally.
    --&gt;
    &lt;condition property="sf.username" value=""&gt; &lt;not&gt; &lt;isset property="sf.username"/&gt; &lt;/not&gt; &lt;/condition&gt;
    &lt;condition property="sf.password" value=""&gt; &lt;not&gt; &lt;isset property="sf.password"/&gt; &lt;/not&gt; &lt;/condition&gt;
    &lt;condition property="sf.sessionId" value=""&gt; &lt;not&gt; &lt;isset property="sf.sessionId"/&gt; &lt;/not&gt; &lt;/condition&gt;

    &lt;taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce"&gt;
        &lt;classpath&gt;
            &lt;pathelement location="ant-salesforce.jar" /&gt;        	
        &lt;/classpath&gt;
    &lt;/taskdef&gt;
			

    &lt;!-- Deploy code and run tests.  If test fails, rollback deploy. --&gt;
    &lt;target name="deployCodeAndRunTests"&gt;
      &lt;sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="..\src" testLevel="RunAllTestsInOrg" rollbackOnError="true" logType="Debugonly"/&gt;
    &lt;/target&gt;
		
&lt;/project&gt;

</pre>
&nbsp;

Create “build.properties” inside the deploy folder and paste the following
<pre># build.properties
#

# Specify the login credentials for the desired Salesforce organization
sf.username = yourUser
sf.password = YouPasswordAndSecurityTokenWithNotingInBetween
#sf.sessionId = 
#sf.pkgName = 
#sf.zipFile = 
#sf.metadataType = 

# Use 'https://login.salesforce.com' for production or developer edition (the default if not specified).
# Use 'https://test.salesforce.com for sandbox.
sf.serverurl = https://login.salesforce.com

sf.maxPoll = 20
# If your network requires an HTTP proxy, see https://ant.apache.org/manual/proxy.html for configuration.
#
</pre>
Make sure you enter the correct credential information for the Salesforce <strong>QA</strong> instance in the code above.

At this point your project structure should look like this

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/23_eclipse_force.bmp"><img class="alignnone wp-image-265" src="https://msdnshared.blob.core.windows.net/media/2016/06/23_eclipse_force.bmp" alt="23_eclipse_force" width="1408" height="589" /></a>

&nbsp;

Update the remote repository with our changes by committing and pushing to VSTS as shown earlier

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/24_commit_changes.bmp"><img class="alignnone wp-image-426" src="https://msdnshared.blob.core.windows.net/media/2016/06/24_commit_changes.bmp" alt="24_commit_changes" width="621" height="518" /></a>

&nbsp;

Now your code in VSTS should look like this

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/25_vsts_repo.bmp"><img class="alignnone wp-image-416" src="https://msdnshared.blob.core.windows.net/media/2016/06/25_vsts_repo.bmp" alt="25_vsts_repo" width="944" height="429" /></a>

&nbsp;

Now we can create a build in VSTS.

Go to “Build” hub in VSTS, and click the (+) icon to create a build

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/26_build_create.bmp"><img class="alignnone wp-image-406" src="https://msdnshared.blob.core.windows.net/media/2016/06/26_build_create.bmp" alt="26_build_create" width="898" height="302" /></a>

Click the option to start with empty template

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/27_select_template.bmp"><img class="alignnone wp-image-405" src="https://msdnshared.blob.core.windows.net/media/2016/06/27_select_template.bmp" alt="27_select_template" width="512" height="568" /></a>

&nbsp;

Choose the defaults and then click create:

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/28_createNewBuild.bmp"><img class="alignnone wp-image-395" src="https://msdnshared.blob.core.windows.net/media/2016/06/28_createNewBuild.bmp" alt="28_createNewBuild" width="473" height="525" /></a>

&nbsp;

Click "Add build step..." link

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/29_addBuildStep.bmp"><img class="alignnone wp-image-385" src="https://msdnshared.blob.core.windows.net/media/2016/06/29_addBuildStep.bmp" alt="29_addBuildStep" width="751" height="395" /></a>

Add “Ant” task

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/30_add_ant_task.bmp"><img class="alignnone wp-image-375" src="https://msdnshared.blob.core.windows.net/media/2016/06/30_add_ant_task.bmp" alt="30_add_ant_task" width="619" height="630" /></a>

&nbsp;

Configure the task.  Go to “Ant Build File”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/31_select_path.bmp"><img class="alignnone wp-image-255" src="https://msdnshared.blob.core.windows.net/media/2016/06/31_select_path.bmp" alt="31_select_path" width="939" height="559" /></a>

&nbsp;

Uncheck “Publish to TFS/Team Services”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/32_save_build_definition.bmp"><img class="alignnone wp-image-365" src="https://msdnshared.blob.core.windows.net/media/2016/06/32_save_build_definition.bmp" alt="32_save_build_definition" width="1167" height="540" /></a>

&nbsp;

In Triggers tab, make sure “Continuous Integration” is checked

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/33_save_Build.bmp"><img class="alignnone wp-image-355" src="https://msdnshared.blob.core.windows.net/media/2016/06/33_save_Build.bmp" alt="33_save_Build" width="883" height="369" /></a>

&nbsp;

Click “Save” and name the build “CI Build”

To test the build, click on “Queue Build”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/34_queueBuild.bmp"><img class="alignnone wp-image-455" src="https://msdnshared.blob.core.windows.net/media/2016/06/34_queueBuild.bmp" alt="34_queueBuild" width="840" height="376" /></a>

&nbsp;

Click OK

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/35_QuereBuildOptions.bmp"><img class="alignnone wp-image-345" src="https://msdnshared.blob.core.windows.net/media/2016/06/35_QuereBuildOptions.bmp" alt="35_QuereBuildOptions" width="403" height="319" /></a>

&nbsp;

Check the build log and ensure that it passed

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/36_buildLogs.bmp"><img class="alignnone wp-image-335" src="https://msdnshared.blob.core.windows.net/media/2016/06/36_buildLogs.bmp" alt="36_buildLogs" width="1046" height="589" /></a>

&nbsp;

&nbsp;

&nbsp;

<strong><u>Verify that CI behaves as expected</u></strong>

Create an Apex class along with its unit test in your Salesforce development instance.  Add a class called “Math” and add the following code:
<pre>public with sharing class Math {
    public Math(){
    
    }
    
    public Integer add(Integer a, Integer b){
        return a+b;
    }
}
</pre>
Add a test class called “MathTest” and add the following code:
<pre>@isTest 
private class MathTest {

    static testMethod void addTest() {
       Math m = new Math();
       Integer result = m.add(4, 5);
       System.assertEquals(result, 9);
    }

}
</pre>
&nbsp;

Once you add the code to Salesforce, import the changes to Eclipse by right click on “src” then “Force.com” then choose “Refresh from Server”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/37_refresh_fromServer.bmp"><img class="alignnone wp-image-325" src="https://msdnshared.blob.core.windows.net/media/2016/06/37_refresh_fromServer.bmp" alt="37_refresh_fromServer" width="787" height="665" /></a>

&nbsp;

Once done, commit and push.  This should trigger the build.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/38_commit_changes.bmp"><img class="alignnone wp-image-315" src="https://msdnshared.blob.core.windows.net/media/2016/06/38_commit_changes.bmp" alt="38_commit_changes" width="554" height="465" /></a>

&nbsp;

To verify the build has been triggered, login to VSTS and go to the “Build” hub, click on “CI Build” then click on Queued tab.  If you don’t see anything in the list, there is a good chance that the build has already completed.  You can check completed builds by clicking on “Completed” tab

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/39_verifyBuildTriggered.bmp"><img class="alignnone wp-image-305" src="https://msdnshared.blob.core.windows.net/media/2016/06/39_verifyBuildTriggered.bmp" alt="39_verifyBuildTriggered" width="1032" height="344" /></a>

&nbsp;

This would deploy code to the Salesforce QA instance.  To check the status in Salesforce, login to Salesforce, then go to “Setup” and then “Monitor” then “Deployment Status”

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/40_sf_deployResults.bmp"><img class="alignnone wp-image-295" src="https://msdnshared.blob.core.windows.net/media/2016/06/40_sf_deployResults.bmp" alt="40_sf_deployResults" width="900" height="384" /></a>

&nbsp;

Let’s simulate a deploy failure by intentionally making the test case fail.  In your Salesforce development instance, replace the code inside MathTest with this
<pre>@isTest 
private class MathTest {

    static testMethod void addTest() {
       Math m = new Math();
       Integer result = m.add(4, 5);
       System.assertEquals(result, 10);
    }

}
</pre>
&nbsp;

Commit and push.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/41_vsts_buildFail.bmp"><img class="alignnone wp-image-285" src="https://msdnshared.blob.core.windows.net/media/2016/06/41_vsts_buildFail.bmp" alt="41_vsts_buildFail" width="897" height="600" /></a>

&nbsp;

Checking the deploy status in Salesforce QA instance

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/42_sf_deploty_fail.bmp"><img class="alignnone wp-image-275" src="https://msdnshared.blob.core.windows.net/media/2016/06/42_sf_deploty_fail.bmp" alt="42_sf_deploty_fail" width="896" height="426" /></a>

&nbsp;

Also, if you go to the code, you will notice that the change made in development instance was not deployed to the QA instance.  We have just implemented CI for Salesforce metadata using VSTS.

We just showed how you can store Salesforce Metadata in VSTS git repository.  We also showed how to setup Continuous Integration and deploy Salesforce Metadata to a QA environment.   Please leave us your feedback.]]></content:encoded>
    </item>
  </channel>
</rss>