Skip to content

Instantly share code, notes, and snippets.

@eydelrivero
Forked from IlyaFinkelshteyn/clone-environment.ps1
Last active May 20, 2020 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eydelrivero/69ede85b15cd02a0e9183628313649c4 to your computer and use it in GitHub Desktop.
Save eydelrivero/69ede85b15cd02a0e9183628313649c4 to your computer and use it in GitHub Desktop.
$apiBaseUrl = 'https://ci.appveyor.com/api/account/<ACCOUNT_NAME>'
$token = '<API_TOKEN>'
$sourceEnvironmentName = '<SOURCE_ENVIRONMENT_NAME>'
Write-Host "$apiBaseUrl/environments"
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
# get source environment ID
$sourceEnvironmentId = ((Invoke-RestMethod -Uri "$apiBaseUrl/environments" -Headers $headers -Method Get) | where {$_.name -eq $sourceEnvironmentName}).deploymentEnvironmentId
# get source environment properies
$source = Invoke-RestMethod -Uri "$apiBaseUrl/environments/$sourceEnvironmentId/settings" -Headers $headers -Method Get
# optionally update name
$source.environment.name = ($source.environment.name + " - NEW")
# create new environment with properies from the source
Invoke-RestMethod -Uri "$apiBaseUrl/environments" -Headers $headers -Body ($source.environment | ConvertTo-Json -Depth 10) -Method Post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment