Azure Fundamentals: Automatically publish Cloudservices with PowerShell

Source: Internet
Author: User

In the software development process, automated compilation and deployment can bring many advantages. Let's talk about how to automate the release of cloud applications on Azure to cloud services.

Package The content you want to publish

First, using MSBuild to compile the *.ccproj file, we need to use the resulting product:
App.publish\xxx.cspkg
App.publish\yyy.cscfg

Download publishsettings file

You can download the Publishsettings file (International Version) by logging in to the address below using your Azure account:
Https://manage.windowsazure.com/publishsettings/index

The name of the file to be downloaded is probably the same:
Xxx1-31-2017-credentials.publishsettings
The previous XXXX is your subscription name.

Another option is to use the PowerShell command get-azurepublishsettingsfile to download the Publishsettings file, which is similar to the above.

Installing the Azure module for PowerShell

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

Create a script for automatic publishingImport Azure Module

Import-module Azure

set the variables used in the script
$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 publication$deploymentLabel= "Your Demplyment label"
Import Publish Settings

The subscription information and the authentication information used to log in are recorded in the Publish settings file, so import this information first.
Import-azurepublishsettingsfile Publishsettings-file-path

It is best to check before importing, to see if the file corresponding to the subscription has been imported.

  $thisSubscriptionExist  =  $False  Span style= "COLOR: #800080" > $subs  = Get-azuresubscription  if  ( $subs . Count -gt  0) { foreach  ( $sub  in  $ Subs  ) { if  ( $sub . Subscriptionname -eq   $subscription    $thisSubscriptionExist  =  $True  }}}  

If it does not exist, perform the import operation, or you can proceed directly to the next step.

if (! $thisSubscriptionExist ) {    Import$subscriptionSetting    // Add a Storage account    Set for subscription $storage$subscription}
set the current subscription

As we can see from the previous step, you may have saved multiple subscription of information on your machine at the same time. So when we perform a publish operation, which subscription information is used by default? Here is a concept of the current subscription, which is published using the information of the current subscription. So be sure to set the subscription used for this release as the current subscription before publishing.
Select-azuresubscription-subscriptionname $subscription –current

Check if 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, execute the new-azuredeployment command. If deployment already exists, execute the set-azuredeployment command.

$deployment $service $slot -errorvariable A-erroraction silentlycontinueif ($deployment-ne $null {    #  deployment already exists and is updated with the Set-azuredeployment command.  }else{    #  required to create a new deployment using the New-azuredeployment command }
New Deployment
$slot $package $configuration $deploymentLabel $service ; $completeDeployment $service $slot ; Check whether the deployment was successful $completeDeploymentID$completeDeployment. Deploymentid;
update a deployment that already exists
$slot $package $configuration $deploymentLabel $service -Force; $completeDeployment $service $slot ; Check whether the deployment was successful $completeDeploymentID$completeDeployment. Deploymentid;
View published results from the web

Once the release is complete, we can also view the results of the publication from the website.

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 us to automate the release of use, as long as we organize these commands into scripts.

Azure Fundamentals: Automatically publish Cloudservices with PowerShell

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.