Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Last active December 22, 2020 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/27cd01f71ec27d8f1f09cf2ddd228bd6 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/27cd01f71ec27d8f1f09cf2ddd228bd6 to your computer and use it in GitHub Desktop.
$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

@PVXDevOps Thanks a lot, updated!

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