Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$token = '<API_TOKEN>'
$sourceEnvironmentName = '<SOURCE_ENVIRONMENT_NAME>'
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
# get source environment ID
$sourceEnvironmentId = ((Invoke-RestMethod -Uri "https://ci.appveyor.com/api/environments" -Headers $headers -Method Get) | where {$_.name -eq $sourceEnvironmentName}).deploymentEnvironmentId
# get source environment properies
$source = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/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 'https://ci.appveyor.com/api/environments' -Headers $headers -Body ($source.environment | ConvertTo-Json -Depth 10) -Method Post
@PVXDevOps
Copy link

PVXDevOps commented Jun 26, 2017

Ilya, thank you for an example, please update for further usage:
FROM

$sourceEnvironmentId = ((Invoke-RestMethod -Uri "https://ci.appveyor.com/api/environments" -Headers $headers -Method Get) | where {$_.name -eq "iis2"}).deploymentEnvironmentId

TO

$sourceEnvironmentId = ((Invoke-RestMethod -Uri "https://ci.appveyor.com/api/environments" -Headers $headers -Method Get) | where {$_.name -eq $sourceEnvironmentName}).deploymentEnvironmentId

@IlyaFinkelshteyn
Copy link
Author

IlyaFinkelshteyn commented Jun 26, 2017

@PVXDevOps Thanks a lot, updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment