Publishing with PowerShell automation cloudservices

Source: Internet
Author: User

In the software development process, automated compilation and deployment can bring many advantages. If you can automate the deployment of software through a single script, you can save a lot of time to do other things.

Here's how to automate publishing cloud applications to Azure's cloud services via PowerShell.

First, packaging needs to publish content

First use MSBuild to compile the *.ccproj file, in all the generated files, we need to use the following two:

App.publish\xxx.cspkg

App.publish\yyy.cscfg

Second, download publishsettings file

There are two ways to download the Publishsettings file:

1. If you do not have an azure account, you will need to register your account, and if you already have an Azure account, you can download the Publishsettings file (International Version) directly by logging in to the address below:

Https://manage.windowsazure.com/publishsettings/index

filename of file downloaded to:

Xxx5-18-2016-credentials.publishsettings

where xxx is your subscription name.

2. Execute the get-azurepublishsettingsfile command in PowerShell to achieve the purpose of downloading the publishsettings file.

Iii. Installing the Azure module for PowerShell

To access the https://azure.microsoft.com/en-us/downloads/#cmd-line-tools URL, click "Command-Line Tools->powershell" below " Windows Install to download the installation package.

Run the installation package and install Azure modules.

Iv. creating a script for automatic publishing

1. Import the Azure module

Executing commands in PowerShell Import-module Azure, importing Azure Module

2, set the variables used in the script, some parameter variables need to be set according to their own information

$package = app.publish\xxx.cspkg

$configuration = App.publish\yyy.cscfg

# Subscription Name

$subscription = "Your subscription name";

# Service Name

$service = "Your service name";

# Storage Account

$storage = "Your storage account";

# slot name, usually first sent to staging, check and then switch

$slot = "Staging";

# provide a descriptive message for each release

$deploymentLabel = "Your Demplyment label"

3, Import publish Settings

Because the subscription information and the authentication information used for the login are recorded in the Publish settings file, you need to import this information first.

Execute command: Import-azurepublishsettingsfile publishsettings-file-path

It is important to note that:

Before importing, you need to check to see if the subscription of this file has been imported and can be verified by the following command.

$thisSubscriptionExist = $False

$subs = Get-azuresubscription

if ($subs. COUNT-GT 0)
{
Foreach ($sub in $subs)
{
if ($sub. Subscriptionname-eq $subscription)
{
$thisSubscriptionExist = $True
}
}
}

If it does not exist, an import operation is required, and if so, proceed directly to the next step.

if (! $thisSubscriptionExist)
{
Import-azurepublishsettingsfile $subscriptionSetting
Add a storage account for subscription
Set-azuresubscription-currentstorageaccount $storage-subscriptionname $subscription
}

4, set the current subscription

As you can see from the previous step, multiple subscription information may be stored on the machine at the same time. So, when performing a publish operation, which subscription information is used by default? The concept of "current subscription" exists here, and the publish operation is published using the information of the current subscription. Therefore, be sure to set the subscription used by this publication as the current subscription before you publish the operation.

Execute select-azuresubscription-subscriptionname $subscription –current command to set

5, check whether deployment exists

Before you perform the deployment, you need to check the existence of deployment, which can affect how you deploy later. If deployment does not exist, you need to establish deployment first. If deployment already exists, you need to update deployment.

The command logic is as follows:

$deployment = get-azuredeployment-servicename $service-slot $slot-errorvariable a-erroraction silentlycontinue

if ($deployment. Name-ne $null)

{

# Deployment already exists and is updated with the Set-azuredeployment command, the 7th step details

}

Else

{

# to create a new deployment using the New-azuredeployment command, the 6th step will detail

}

6. Create a new deployment and check if the deployment is successful

New-azuredeployment-slot $slot-package $package-configuration $configuration-label $deploymentLabel-servicename $ Service

$completeDeployment = Get-azuredeployment-servicename $service-slot $slot;

Check whether the deployment was successful

$completeDeploymentID = $completeDeployment. Deploymentid;

7. Update the existing deployment and check the success of the deployment command

Set-azuredeployment-upgrade-slot $slot-package $package-configuration $configuration-label $deploymentLabel- ServiceName $service-force;

$completeDeployment = Get-azuredeployment-servicename $service-slot $slot;

Check whether the deployment was successful

$completeDeploymentID = $completeDeployment. Deploymentid;

8. View the published results from the website

After publishing is complete, you can view the published results from the Web site.

Where the Deployment label is set in the publish script and is typically written to the release date and version number; The Deployment ID is the GUID that identifies this deployment.

To summarize, the Azure module for PowerShell has provided a well-established command for our automated release use, and we only need to organize these commands into scripts.

Publishing with PowerShell automation cloudservices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.