Skip to content

Instantly share code, notes, and snippets.

View Dalmirog-zz's full-sized avatar

Dalmiro Granas Dalmirog-zz

View GitHub Profile
@Dalmirog-zz
Dalmirog-zz / Remove-OctopusLifeCycle.ps1
Last active August 29, 2015 14:12
Octopus - Delete LifeCycle using REST API
#Change dll path accordingly
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Newtonsoft.Json.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Octopus.Client.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Octopus.Platform.dll"
#Connection data
$apikey = "YOUR-API"
$OctopusURI = "http://YourOctopusURL"
$headers = @{"X-Octopus-ApiKey"="$($apikey)";}
@Dalmirog-zz
Dalmirog-zz / Update-StepTemplatesOnDeploymentProcesses.ps1
Last active September 14, 2015 22:42
Update-StepTemplatesOnDeploymentProcesses (nice name, i know)
<#
.Synopsis
Updates the Step Templates used on Deployment Processes to the latest versions
.DESCRIPTION
Step templates can be updated from the library on Octopus, but that doesnt mean that the Deployment processes using that template will start using the latest version right away. Normally, the user would have to update the step template on each deployment process manually. This script takes care of that.
.EXAMPLE
Update-StepTemplatesOnDeploymentProcesses -ActionTemplateID "ActionTemplates-3" -OctopusURI "http://localhost" -APIKey "API-RLMWLZBPMX5DRPLCRNZETFS4HA"
.EXAMPLE
Update-StepTemplatesOnDeploymentProcesses -AllActionTemplates -OctopusURI "http://Octopusdeploy.MyCompany.com" -APIKey "API-TSET42BPMX5DRPLCRNZETFS4HA"
.LINK
@Dalmirog-zz
Dalmirog-zz / Get-OctopusUsersAndTentaclesCount
Created January 21, 2015 18:15
Gets count of Octopus Users and Tentacles on a specific instance
#make sure this path is correct on your machine
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Newtonsoft.Json.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Octopus.Client.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Octopus.Platform.dll"
$OctopusURI = "" #i.e "Http://Octopus.MyAwesomeCompany.com"
$apikey = "" #i.e "API-7CH6XN0HHOU7DDEEUGKUFUR1K"
$endpoint = new-object Octopus.Client.OctopusServerEndpoint "$($OctopusURI)","$($apikey)"
$repository = new-object Octopus.Client.OctopusRepository $endpoint
@Dalmirog-zz
Dalmirog-zz / EmailWithRetry.ps1
Created January 23, 2015 19:47
Easily readable snipped to send email and retry X times in case of failure
$Try = 0
$MaxRetries = 5
$SecsBeforeRetry = 5
$PSEmailServer = "smtp.company.com"
$from = "Me@company.com"
$to = "You@company.com"
$subject = "Amazing Subject"
$body = "Interesting stuff"
do{
@Dalmirog-zz
Dalmirog-zz / CloneOctopusProject.ps1
Created January 25, 2015 04:41
Clone Octopus Project
Add-Type -Path "C:\Tools\Newtonsoft.Json.dll"
Add-Type -Path "C:\Tools\Octopus.Client.dll" #Make sure its version 2.6.x or higher. Otherwhise you'll get errors with the LifecycleId property
Add-Type -Path "C:\Tools\Octopus.Platform.dll"
$OctopusURI = "" #i.e "Http://Octopus.MyAwesomeCompany.com"
$apikey = "" #i.e "API-7CH6XN0HHOU7DDEEUGKUFUR1K"
$endpoint = new-object -TypeName Octopus.Client.OctopusClient(New-Object Octopus.Client.OctopusServerEndpoint($OctopusURI,$apikey))
$repository = new-object Octopus.Client.OctopusRepository $endpoint
@Dalmirog-zz
Dalmirog-zz / CloneOctopusProject.cs
Created January 25, 2015 04:46
Clone Octopus Project (C#)
var client = new OctopusClient(new OctopusServerEndpoint(octoUrl, apiKey));
var repo = new OctopusRepository(client);
var project = repo.Projects.FindByName("MyOriginalProject");
var newProject = new ProjectResource
{
Name = "MyClonedProject",
Description = "Cloned copy",
ProjectGroupId = project.ProjectGroupId,
@Dalmirog-zz
Dalmirog-zz / gist:b6264c8b7d61a2e1398a
Last active September 22, 2015 12:31
New Incremental Release with prompt variable
$apiKey = "Your API Key"
$OctopusURL = "Your Octopus URL"
$Header = @{ "X-Octopus-ApiKey" = $apiKey }
$ProjectName = "Your Project Name"
$EnvironmentName = "Your Environment Name"
#Getting Environment and Project By Name
$Project = Invoke-WebRequest -Uri "$OctopusURL/api/projects/$ProjectName" -Headers $Header| ConvertFrom-Json
@Dalmirog-zz
Dalmirog-zz / gist:4b45994a2c5f782fd0b4
Last active July 22, 2018 23:53
Block Octopus Release
$apiKey = "Your API Key"
$OctopusURL = "Your Octopus URL"
$Header = @{ "X-Octopus-ApiKey" = $apiKey }
#Release you want to block
$ReleaseID = "Your Release ID" #i.e. releases-2610
$body = @{description="This is the description for the blocking"} | ConvertTo-Json
@Dalmirog-zz
Dalmirog-zz / Set-OctopusMaintenanceMode.ps1
Created February 6, 2015 19:25
Set-OctopusMaintenanceMode
$apiKey = "Your API Key"
$OctopusURL = "Your Octopus URL"
$MaintenanceMode = "True" #Only accepts "True" or "False". Values must be strings
$Header = @{ "X-Octopus-ApiKey" = $apiKey }
$body = @{IsInMaintenanceMode=$MaintenanceMode} | ConvertTo-Json
Invoke-WebRequest -Uri "$OctopusURL/api/maintenanceconfiguration" -Method PUT -Headers $Header -Body $body
@Dalmirog-zz
Dalmirog-zz / Stop-OctopusTask.ps1
Created February 10, 2015 18:07
Cancel Octopus Task
$OctopusURI = "Your Octopus URI"
$OctopusAPIKey = "Your Octopus APIKey"
$TaskID = "Task ID" #Task ID to cancel asociated with the deployment. e.g "Servertasks-3567"
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }
Invoke-WebRequest -Uri "$OctopusURI/api/tasks/$TaskID/cancel" -Method Post -Headers $Header