The Azure Code Samples are currently available in English

Manage Azure websites with Ruby

Laatst bijgewerkt: 27-9-2016
Bewerken op GitHub

This sample demonstrates how to manage your Azure websites using a ruby client.

On this page

1. If you don't already have it, install Ruby and the Ruby DevKit.

  1. If you don't have bundler, install it.

    gem install bundler
  2. Clone the repository.

    git clone
  3. Install the dependencies using bundle.

    cd app-service-web-ruby-manage
    bundle install
  4. Create an Azure service principal either through Azure CLI, PowerShell or the portal.

  5. Set the following environment variables using the information from the service principle that you created.

    export AZURE_TENANT_ID={your tenant id}
    export AZURE_CLIENT_ID={your client id}
    export AZURE_CLIENT_SECRET={your client secret}
    export AZURE_SUBSCRIPTION_ID={your subscription id}

    [AZURE.NOTE] On Windows, use set instead of export.

  6. Run the sample.

    bundle exec ruby example.rb

What does example.rb do?

The sample creates, lists and updates a website. It starts by setting up a ResourceManagementClient object using your subscription and credentials.

subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] || '11111111-1111-1111-1111-111111111111' # your Azure Subscription Id
provider =
credentials =
web_client =
resource_client =
resource_client.subscription_id = web_client.subscription_id = subscription_id

The sample then sets up a resource group in which it will create the website.

resource_group_params = do |rg|
  rg.location = WEST_US


resource_client.resource_groups.create_or_update(GROUP_NAME, resource_group_params)

Create a server farm

Create a server farm to host your website.

server_farm_params = do |sf|
  sf.location = WEST_US
  sf.sku = do |sd| = 'S1'
    sd.capacity = 1
    sd.tier = 'Standard'
print_item web_client.server_farms.create_or_update_server_farm(GROUP_NAME, SERVER_FARM_NAME, server_farm_params)

Create a website

site_params = do |site|
  site.location = WEST_US = do |props|
web_client.sites.create_or_update_site(GROUP_NAME, SITE_NAME, site_params)

List websites in the resourcegroup

web_client.sites.get_sites(GROUP_NAME).each{ |site| print_item site }

Get details for the given website

web_client.sites.get_site(GROUP_NAME, SITE_NAME)

Delete a website

web_client.sites.delete_site(GROUP_NAME, SITE_NAME)

At this point, the sample also deletes the resource group that it created.


More information

Please refer to Azure SDK for Ruby for more information.