Azure Devops job to Clone Kontent.AI Project

Create a Pipeline in Azure Devops, which will run on window-latest agent.

Configuration values that will be used are:

  • Azure Service Connection
  • Kontent Project Id
  • Kontent Management API Key

You will need to use the Kontent Management API: https://manage.kontent.ai/v2/projects/{ProjectId}/clone-environment

Payload will be

{
 "name": "{name of new project}"
 "roles_to_activate: [comma seperated guids from the env you cloning],
  "copy_data_options" : {
     "content_items_assets": "true",
     "content_item_version_history": "false"
   }
}

Using powershell scripting invoke the API

$response = Invoke-WebRequest -Uri $uri -Method POST -ContentType application/Json -Headers $headers -Body $payload

$cloneResponseContent = ConvertFrom-Json $response.Content

New project Id = $cloneResponseContent .id

New Management API Key = $cloneResponseContent.management_api_key

Check Clone progress

Poll the API using a poll interval to check Clone Progress

API $uri = “https://manage.kontent.ai/v2/projects/{newProjectId}/environment-cloning-state”

$progressStatus = Invoke-WebRequst -Uri $uri -Method Get -ContentType application/Json -Headers {“Authorization”=”Bearer {newManagementApiKey}”

$progressContent = ConverFrom-Json $progressResponse.Content

Check until $progressContent -eq “in_progress” and on success should be “done”

As part of post script you can perform following tasks:

  • Delete Webhooks
  • Create Webhook
  • Set New Roles and permissions