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 / script.ps1
Created August 23, 2015 21:36
Create Lifecycle
$lifecycle = New-Object Octopus.Client.Model.LifecycleResource
$lifecycle.Name = "MyLifecycle"
#Default Retention Policy
$lifecycle.ReleaseRetentionPolicy = [Octopus.Platform.Model.RetentionPeriod]::new(0,[Octopus.Platform.Model.RetentionUnit]::Items) #Unlimmited Releases
#$lifecycle.ReleaseRetentionPolicy = [Octopus.Platform.Model.RetentionPeriod]::new(2,[Octopus.Platform.Model.RetentionUnit]::Days) #2 days
$lifecycle.TentacleRetentionPolicy = [Octopus.Platform.Model.RetentionPeriod]::new(0,[Octopus.Platform.Model.RetentionUnit]::Items)
#$lifecycle.TentacleRetentionPolicy = [Octopus.Platform.Model.RetentionPeriod]::new(10,[Octopus.Platform.Model.RetentionUnit]::Days) #10 days
New-OctopusResource -Resource $lifecycle
@Dalmirog-zz
Dalmirog-zz / script.ps1
Created August 23, 2015 21:34
Adding variable to variable set
####Adding a new variable#####
$variableset = Get-OctopusVariableSet -Projectname Powershell -ResourceOnly
$newvariable = New-Object Octopus.Client.Model.VariableResource
$scope = New-Object Octopus.Platform.Model.ScopeSpecification
#Environment Scope
#$scope.Add([Octopus.platform.Model.Scopefield]::Environment,(New-Object Octopus.Platform.Model.ScopeValue("Environments-1")))
@Dalmirog-zz
Dalmirog-zz / script.ps1
Created August 23, 2015 21:31
Update Existing variable
#####Update existing variable#####
$variableset = Get-OctopusVariableSet -Projectname Powershell -ResourceOnly
#updating value of variable "OctopusPrintVariables" to "False"
$variableset.Variables | ?{$_.name -eq "OctopusPrintVariables"} | %{$_.value = "False"}
#update variable set on database
Update-OctopusResource -Resource $variableset -Force
@Dalmirog-zz
Dalmirog-zz / wait.ps1
Last active August 29, 2015 14:27
Wait
[string]$LockFile = "C:\Test\Lockfile.txt"
[int]$wait = 15 #seconds to wait before checking the content of $lockfile again.
#Creating $lockfile if it doesnt exist
If ((Test-Path $LockFile) -eq $false){
Write-Output "$lockfile does not exist on $env:computername. Creating it..."
New-Item $LockFile -ItemType file -Verbose
"Available" | Out-File $LockFile
}
@Dalmirog-zz
Dalmirog-zz / addremoveroles.ps1
Created August 10, 2015 17:57
Bulk add/remove roles
##Module URL: http://dalmirog.github.io/OctoPosh/
##Function to add roles
function add-Machineroles([string]$rolename){
$machines = Get-OctopusMachine
foreach ($machine in $machines)
{
$machine.resource.roles.add($rolename)
}
@Dalmirog-zz
Dalmirog-zz / GetDeployments.ps1
Created August 10, 2015 16:18
Get latest deployments and sort them
$projects = Get-OctopusProject
$list = @()
$list += $projects.latestdeployments
#Presentation
#If all "Prod" environments name start with "Prod", they will all show up toghether
$list | Sort-Object EnvironmentName | Format-Table
#If all "Web" Projects name start with "Web", they will all show up toghether
@Dalmirog-zz
Dalmirog-zz / script.sql
Created August 4, 2015 19:40
Get Built In directory path from SQL
use "NameOfYourOctopusDatabase" /* <-- Change this */
select JSON from Configuration
where id = 'builtinrepositoryconfigurations-single'
@Dalmirog-zz
Dalmirog-zz / RolesExamples.ps1
Last active September 2, 2015 15:39
Examples of updating machine roles using Octoposh
## 1) Updating a Machine's roles
#getting the machine
$machine = Get-OctopusMachine -MachineName "MyMachine"
#updating the machine's roles
$machine.resource.roles.add("NewRoleToAdd")
$machine.resource.roles.Remove("OldRoleToRemove")
#Saving the machine resource on the database
@Dalmirog-zz
Dalmirog-zz / variables.json
Created July 28, 2015 16:09
Example of variables file for Add-OctopusVariables
{
"Variables": [
{
"Name": "Variable1",
"Value": "Valuewow",
"Scope": {
"Environment": [
"Staging"
],
"Machine": [
@Dalmirog-zz
Dalmirog-zz / MSDeployStep.json
Created July 25, 2015 22:15
MSDeploy Library step with fix for Null or Empty SkipSyncPaths
{
"Id": "ActionTemplates-321",
"Name": "Web Deploy - Publish Website (MSDeploy)",
"Description": "Ensure that Web Deploy 3.5 is installed on the system. The installer is downloaded from http://www.iis.net/downloads/microsoft/web-deploy if required.",
"ActionType": "Octopus.Script",
"Version": 1,
"Properties": {
"Octopus.Action.Script.ScriptBody": "[System.Reflection.Assembly]::LoadWithPartialName(\"Microsoft.Web.Deployment\")\r\n\r\n# A collection of functions that can be used by script steps to determine where packages installed\r\n# by previous steps are located on the filesystem.\r\n \r\nfunction Find-InstallLocations {\r\n $result = @()\r\n $OctopusParameters.Keys | foreach {\r\n if ($_.EndsWith('].Output.Package.InstallationDirectoryPath')) {\r\n $result += $OctopusParameters[$_]\r\n }\r\n }\r\n return $result\r\n}\r\n \r\nfunction Find-InstallLocation($stepName) {\r\n $result = $OctopusParameters.Keys | where {\r\n $_.Equals(\"Octopus.Action