├── .gitignore ├── Deployment-Scripts └── Powershell │ └── AzureCSWaitForInstanceSwap.ps1 ├── LICENSE.txt ├── Machine-Policy-Scripts └── ValidateRolesInMachine.ps1 ├── Octopus.Client ├── Csharp │ ├── Accounts │ │ ├── CreateAzureServicePrincipal.cs │ │ └── CreateGoogleCloudAccount.cs │ ├── Artifacts │ │ └── DownloadRunbookArtifact.cs │ ├── BulkOperations │ │ └── BulkAddTenantsToProject.cs │ ├── Certificates │ │ ├── CreateCertificate.cs │ │ └── ReplaceCertificate.cs │ ├── Channels │ │ └── CreateChannel.cs │ ├── DeploymentProcesses │ │ ├── AddEnvironmentConditionToStep.cs │ │ ├── CreateScriptStep.cs │ │ ├── GetStepsUsingPackage.cs │ │ └── GetStepsUsingRole.cs │ ├── Deployments │ │ ├── CancelDeploymentsBasedOnTimeOrInactivity.cs │ │ ├── CancelQueuedDeployments.cs │ │ ├── CreateDeploymentWithPromptVariables.cs │ │ ├── CreateReleaseAndDeployment.cs │ │ ├── CreateReleaseAndDeploymentWithTenants.cs │ │ ├── DeployRelease.cs │ │ ├── PackagesDeployedToEnvironmentFromVariables.cs │ │ └── RetrievePagedListOfDeploymentsToEnvironment.cs │ ├── Environments │ │ └── AddEnvironments.cs │ ├── Feeds │ │ ├── ChangeFeed.cs │ │ ├── CreateFeed.cs │ │ ├── DeleteFeed.cs │ │ ├── DownloadPackage.cs │ │ ├── FindPackagesFromFeed.cs │ │ ├── GetAllFeeds.cs │ │ └── PushPackage.cs │ ├── Lifecycles │ │ └── CreateLifecycle.cs │ ├── Machines │ │ └── README.md │ ├── ProjectGroups │ │ └── CreateProjectGroup.cs │ ├── Projects │ │ ├── AddStepTemplate.cs │ │ ├── CloneProject.cs │ │ ├── CreateProject.cs │ │ ├── DeleteProjectByName.cs │ │ ├── DeleteProjectsWithoutDeploymentProcess.cs │ │ ├── DisableProjectTriggers.cs │ │ ├── FindUnusedProjects.cs │ │ └── ProjectsNotDeployedToEnvironment.cs │ ├── Releases │ │ ├── CreateAndDeployRelease.cs │ │ ├── CreateRelease.cs │ │ ├── DeleteReleasesForProject.cs │ │ ├── PromoteReleasesNotInDestination.cs │ │ └── UpdateReleaseVariableSnapshot.cs │ ├── Runbooks │ │ ├── AddScriptStepToRunbookProcess.cs │ │ ├── CreateAndPublishRunbookSnapshot.cs │ │ ├── CreateRunbook.cs │ │ ├── CreateScheduledRunbookTrigger.cs │ │ ├── PublishRunbook.cs │ │ ├── RunRunbook.cs │ │ └── RunRunbookWithPromptedVariables.cs │ ├── Spaces │ │ ├── AddSpaceWithEnvironments.cs │ │ └── DeleteSpace.cs │ ├── StepTemplates │ │ └── UpdateStepTemplatesInProcesses.cs │ ├── Tagsets │ │ └── CreateTagset.cs │ ├── Targets │ │ ├── AddRoleToTarget.cs │ │ ├── ChangeTargetMachinePolicy.cs │ │ ├── CheckForTentacleUpgrades.cs │ │ ├── CreateAzureWebApp.cs │ │ ├── DeleteMachinesByRole.cs │ │ ├── DeleteTargetByName.cs │ │ ├── EnableOrDisableAMachine.cs │ │ ├── RegisterListeningTentacle.cs │ │ ├── RegisterPollingTentacle.cs │ │ └── UpgradeTargets.cs │ ├── Tasks │ │ ├── GetTaskErrorDetails.cs │ │ └── RunHealthCheck.cs │ ├── Teams │ │ ├── AddEnvironmentToTeam.cs │ │ ├── FindTeamsWithUserRole.cs │ │ └── RemoveProjectFromTeam.cs │ ├── Tenants │ │ ├── CreateTenant.cs │ │ └── UpdateMultipleTenantVariablesWithSingleValue.cs │ ├── Users │ │ ├── AddAzureActiveDirectoryLoginToUsers.cs │ │ ├── CreateAPIKey.cs │ │ ├── FindUsersWithEditRoles.cs │ │ ├── FindUsersWithUserRole.cs │ │ └── ListUsers.cs │ └── Variables │ │ ├── AddLibraryVariableSetToSelectedProjects.cs │ │ ├── ClearSensitiveVariables.cs │ │ ├── FindProjectsThatUseALibraryVariableSet.cs │ │ ├── FindVariableSetVariableUsage.cs │ │ ├── FindVariableUsage.cs │ │ ├── FindVariableValueUsage.cs │ │ ├── GetAllProjectAndLibraryVariablesWithScopes.cs │ │ ├── ModifyOrAddVariableToProject.cs │ │ └── UpdateLibraryVariableSetVariableValue.cs ├── LINQPad │ ├── CheckMigratoinRequirementsForLvsChange.linq │ ├── CloneRunbookAcrossProjects.linq │ ├── Copy_step_between_projects.linq │ ├── CreateLibraryVariableSetAndAddToAllProjects.linq │ ├── Get task details for all deployments of a release.linq │ ├── GetInUsePackages.linq │ ├── GetMachineNamesFromDeployment.linq │ ├── GetPackagesInEnvironment.linq │ ├── ImportExportUpdateVariables.linq │ ├── ListPackageVersionsUsedInRelease.linq │ ├── Push Package to Built-In Repository.linq │ └── WorkInADifferentSpace.linq ├── PowerShell │ ├── Accounts │ │ ├── CreateAzureServicePrincipal.ps1 │ │ ├── CreateGoogleCloudAccount.ps1 │ │ └── findAzureAccountUsage.ps1 │ ├── BulkOperations │ │ └── BulkAddTenantsToProject.ps1 │ ├── Certificates │ │ ├── AddEnvironmentRestrictionToCertificate.ps1 │ │ ├── CreateCertificate.ps1 │ │ ├── DeleteDuplicateCertificates.ps1 │ │ └── ReplaceCertificate.ps1 │ ├── Channels │ │ └── CreateChannel.ps1 │ ├── DeploymentProcesses │ │ ├── AddEnvironmentConditionToStep.ps1 │ │ ├── AddMissingStepsToProcess.ps1 │ │ ├── ChangePackageFeedForProjects.ps1 │ │ ├── CreateScriptStep.ps1 │ │ ├── CreateStepBasedOnStepTemplate.ps1 │ │ ├── ExportInlineScriptsToFile.ps1 │ │ ├── GetStepsUsingPackage.ps1 │ │ ├── GetStepsUsingRole.ps1 │ │ ├── RemoveDeploymentProcessStep.ps1 │ │ ├── RemoveRoleFromAllSteps.ps1 │ │ ├── ScopeRoleToStep.ps1 │ │ └── UnwrapChildSteps.ps1 │ ├── Deployments │ │ ├── CancelQueued.ps1 │ │ ├── CreateProjectDeploymentIfNotRunningAlready.ps1 │ │ ├── CreateReleaseAndDeployment.ps1 │ │ ├── CreateReleaseAndDeploymentWithTenants.ps1 │ │ ├── DeployRelease.ps1 │ │ ├── DeployReleaseToTenant.ps1 │ │ ├── GetDeploymentLifecyclePhase.ps1 │ │ ├── PromoteRelease.ps1 │ │ └── RetrievePagedListOfDeploymentsToEnvironment.ps1 │ ├── Environments │ │ └── AddEnvironments.ps1 │ ├── Events │ │ ├── FindByDate.ps1 │ │ └── FindDeployedByUser.ps1 │ ├── Feeds │ │ ├── ChangeFeed.ps1 │ │ ├── CreateFeed.ps1 │ │ ├── DeleteFeed.ps1 │ │ ├── DownloadPackage.ps1 │ │ ├── FindPackagesFromFeed.ps1 │ │ ├── GetAllFeeds.ps1 │ │ ├── PurgeNugetFeeds.ps1 │ │ └── PushPackage.ps1 │ ├── Lifecycles │ │ ├── Add-phase-to-lifecycle.ps1 │ │ ├── CreateLifecycle.ps1 │ │ └── CreateLifecycleWithPhase.ps1 │ ├── Machines │ │ └── README.md │ ├── ProjectGroups │ │ └── CreateProjectGroup.ps1 │ ├── Projects │ │ ├── CreateAutoDeployTriggersForAllProjects.ps1 │ │ ├── CreateProject.ps1 │ │ ├── CreateScriptStepForAllProjects.ps1 │ │ ├── DeleteProjectByName.ps1 │ │ ├── DeleteProjectsWithoutDeploymentProcess.ps1 │ │ ├── DisableAllProjectTriggers.ps1 │ │ └── IgnoreUnavailableMachinesAllProjects.ps1 │ ├── Releases │ │ ├── CreateRelease.ps1 │ │ ├── DeleteReleasesForProject.ps1 │ │ ├── PromoteReleasesNotInDestination.ps1 │ │ └── UpdateReleaseVariableSnapshot.ps1 │ ├── Runbooks │ │ ├── CreateRunbook.ps1 │ │ ├── CreateRunbookScheduledTrigger.ps1 │ │ ├── PublishRunbook.ps1 │ │ └── RunRunbook.ps1 │ ├── ScriptModules │ │ └── MigrateBetweenInstances.ps1 │ ├── Spaces │ │ ├── AddSpaceWithEnvironments.ps1 │ │ └── DeleteSpace.ps1 │ ├── StepTemplates │ │ └── UpdateInDeploymentProcesses.ps1 │ ├── Tagsets │ │ ├── AddTagToTagset.ps1 │ │ └── CreateTagSet.ps1 │ ├── Targets │ │ ├── AddRoleToAllMachines.ps1 │ │ ├── AddRoleToTarget.ps1 │ │ ├── ChangeTargetMachinePolicy.ps1 │ │ ├── CheckForTentacleUpgrades.ps1 │ │ ├── CountMachineAndEnvironments.ps1 │ │ ├── CreateAzureWebApp.ps1 │ │ ├── CreateAzureWebAppTargetsFromSubscription.ps1 │ │ ├── DeleteMachinesByRole.ps1 │ │ ├── DeleteTargetByName.ps1 │ │ ├── EnableOrDisableAMachine.ps1 │ │ ├── ListMachinesInDeployment.ps1 │ │ ├── RegisterListeningTentacle.ps1 │ │ ├── RegisterPollingTentacle.ps1 │ │ └── UpgradeTargets.ps1 │ ├── Tasks │ │ └── RunHealthCheck.ps1 │ ├── Teams │ │ ├── AddEnvironmentToTeam.ps1 │ │ ├── FindTeamsWithUserRole.ps1 │ │ └── RemoveProjectFromTeam.ps1 │ ├── Tenants │ │ ├── CreateTenant.ps1 │ │ ├── UpdateMultipleTenantVariablesWithSingleValue.ps1 │ │ └── UpdateTenantLogo.ps1 │ ├── Users │ │ ├── APIKey_Create.ps1 │ │ ├── AddAzureActiveDirectoryLoginToUsers.ps1 │ │ ├── Find-UsersWithEditRoles.ps1 │ │ ├── FindInactiveUsers.ps1 │ │ ├── FindUsersWithUserRole.ps1 │ │ └── ListUsers.ps1 │ └── Variables │ │ ├── AddLibraryVariableSetToAllProjects.ps1 │ │ ├── AddLibraryVariableSetToSelectedProjects.ps1 │ │ ├── AddVariableToLibraryVariableSet.ps1 │ │ ├── ClearSensitiveVariables.ps1 │ │ ├── Copy-LibraryVariables.ps1 │ │ ├── FindProjectsThatUseALibraryVariableSet.ps1 │ │ ├── FindVariableSetVariableUsage.ps1 │ │ ├── FindVariableUsage.ps1 │ │ ├── FindVariableValueUsage.ps1 │ │ ├── ModifyOrAddVariableToProject.ps1 │ │ ├── RemoveEmptyCollectionsFromScope.ps1 │ │ ├── Update-VariableEnvironments.ps1 │ │ ├── UpdateLibraryVariableSetVariableValue.ps1 │ │ ├── UpdateVariableInProject.ps1 │ │ └── find-variables-scoped-to-steps.ps1 └── java │ ├── lifecycles │ └── create-lifecycle.java │ ├── project-groups │ └── create-project-group.java │ ├── projects │ ├── create-project.java │ └── delete-project-by-name.java │ ├── releases │ └── create-release-with-version.java │ ├── spaces │ ├── add-space-with-environments.java │ └── delete-space.java │ └── users │ └── create-api-key.java ├── README.md └── REST ├── Golang ├── Accounts │ ├── AWSAccounts │ │ └── CreateAWSAccount │ │ │ └── CreateAWSAccount.go │ ├── AzureAccounts │ │ └── CreateAzureAccount │ │ │ └── CreateAzureAccount.go │ └── GoogleCloudAccounts │ │ └── CreateGoogleCloudAccount.go ├── BulkOperations │ └── BulkAddTenantsToProject.go ├── Certificates │ ├── CreateCertificate.go │ └── ReplaceCertificate.go ├── Channels │ └── CreateChannel │ │ └── CreateChannel.go ├── DeploymentProcesses │ ├── AddEnvironmentConditionToStep.go │ ├── CreateScriptStep.go │ ├── GetStepsUsingPackage.go │ └── GetStepsUsingRole.go ├── Deployments │ ├── CancelQueuedDeployments.go │ └── DeployRelease.go ├── Environments │ └── AddEnvironments.go ├── Feeds │ ├── ChangeFeed.go │ ├── CreateNugetFeed.go │ ├── DeleteFeed.go │ ├── GetFeeds.go │ └── PushPackage.go ├── Lifecycles │ └── CreateLifecycle │ │ └── CreateLifecycle.go ├── Project-Groups │ ├── CreateProjectGroups │ │ └── CreateProjectGroup.go │ └── ListProjectGroups │ │ └── listProjectGroups.go ├── Projects │ ├── CreateProjects │ │ └── createProjects.go │ ├── DeleteProjects │ │ ├── DeleteProjectByName.go │ │ └── DeleteProjectsWithoutProcesses.go │ ├── ImportProjects.go │ └── ListProjects │ │ └── listProjects.go ├── Releases │ ├── CreateAndDeployRelease.go │ ├── CreateAndDeployReleaseWithTenants.go │ ├── CreateRelease.go │ ├── DeleteReleasesForProject.go │ └── PromoteReleasesNotInDestination.go ├── Runbooks │ ├── CreateRunbook.go │ └── PublishRunbook.go ├── Spaces │ ├── CreateSpace │ │ └── CreateSpace.go │ └── DeleteSpace.go ├── Tagsets │ └── CreateTagset.go ├── Targets │ ├── AddAzureWebApp.go │ ├── AddRoleToTarget.go │ ├── ChangeTargetMachinePolicy.go │ ├── CheckForTentacleUpgrades.go │ ├── DeleteTargetByName.go │ ├── DeleteTargetByRole.go │ ├── RegisterListeningTentacle.go │ ├── RegisterPollingTentacle.go │ └── UpgradeTargets.go ├── Teams │ ├── AddEnvironmentToTeam.go │ └── RemoveProjectFromTeams.go ├── Tenants │ └── CreateTenants.go ├── Users │ ├── AddAzureActiveDirectoryLoginToUsers.go │ ├── CreateAPIKey.go │ ├── FindUsersWithEditRoles.go │ ├── FindUsersWithRole.go │ └── ListUsers.go ├── Variables │ ├── AddLibraryVariableSetToProjects.go │ ├── ClearSensitiveVariables.go │ ├── FindVariableSetVariableUsage.go │ ├── FindVariableUsage.go │ ├── ModifyOrAddVariableToProject.go │ └── UpdateLibraryVariableSetVariableValue.go ├── go.mod ├── go.sum └── vendor │ └── HashAPIKey │ └── hashpass.go ├── PowerShell ├── Accounts │ ├── CreateAzureServicePrincipal.ps1 │ ├── CreateGoogleCloudAccount.ps1 │ └── RemoveAssociatedTenantFromAccount.ps1 ├── Administration │ ├── CheckForMonoUsage.ps1 │ ├── DrainOddOrEvenOctopusServerNodes.ps1 │ ├── GetMaintenanceModeStatus.ps1 │ ├── GetUsageCounts.ps1 │ └── UpdateMaintenanceModeStatus.ps1 ├── Artifacts │ ├── DeleteDeploymentArtifact.ps1 │ ├── DownloadArtifact.ps1 │ ├── DownloadRunbookArtifact.ps1 │ └── UploadArtifact.ps1 ├── BuildInformation │ └── GetBuildInformationForAllPackagesInRunbook.ps1 ├── BulkOperations │ ├── BulkAddTenantsToProject.ps1 │ └── BulkConvertMultipleProjectsToVersionControl.ps1 ├── Certificates │ ├── CreateCertificate.ps1 │ └── ReplaceCertificate.ps1 ├── Channels │ └── CreateChannel.ps1 ├── DeploymentProcesses │ ├── AddCommunityStepTemplateToProcess.ps1 │ ├── AddEnvironmentConditionToStep.ps1 │ ├── CloneDeploymentProcessStepToAllProjects.ps1 │ ├── CloneProcessStepToProjectInAnotherSpace.ps1 │ ├── CreateScriptStep.ps1 │ ├── EnableDisableStepsbyName.ps1 │ ├── ExtractScriptStepContentToFiles.ps1 │ ├── FindAllProjectsByRole.ps1 │ ├── GetStepsUsingHelmExecutable.ps1 │ ├── GetStepsUsingPackage.ps1 │ ├── GetStepsUsingRole.ps1 │ ├── GetStepsUsingWorkerPool.ps1 │ ├── RemoveARCSettingsFromProject.ps1 │ ├── RemoveInvalidChannelsFromDeploymentProcess.ps1 │ └── UpdateStepOrder.ps1 ├── Deployments │ ├── CancelDeployment.ps1 │ ├── CancelLongRunningTasks.ps1 │ ├── CancelQueuedDeployments.ps1 │ ├── CreateDeploymentWithPromptVariables.ps1 │ ├── CreateReleaseAndDeployToSingleTenant.ps1 │ ├── CreateReleaseAndDeployment.ps1 │ ├── CreateReleaseAndDeploymentSkippingSteps.ps1 │ ├── CreateReleaseAndDeploymentWithTenants.ps1 │ ├── DeleteDeploymentsByRelease.ps1 │ ├── DeployExistingReleaseToSpecificSingleMachine.ps1 │ ├── DeployExistingReleaseToSpecificSingleTenant.ps1 │ ├── DeployRelease.ps1 │ ├── FailDeploymentIfHasWarningsOrErrorsIsTrue.PS1 │ ├── GetLatestDeploymentForAllProjects.ps1 │ ├── GetListOfDeploymentsToSpecificEnvironment.ps1 │ ├── GetReleaseNotesForDeploymentsToEnvironment.ps1 │ ├── ListDeploymentsAsXml.ps1 │ ├── ReDeployLatestReleaseInEnvironment.ps1 │ ├── RetrievePagedListOfDeploymentsToEnvironment.ps1 │ ├── UpdateVariablesThenRedeploy.ps1 │ └── deletedeployment.ps1 ├── Environments │ ├── AddEnvironments.ps1 │ ├── DeleteEnvironments.ps1 │ ├── FindEnvironmentsWithNoDeployments.ps1 │ └── FindUsage.ps1 ├── Events │ ├── FindByDate.ps1 │ └── GetAuditLogForEntity.ps1 ├── Feeds │ ├── ChangeFeed.ps1 │ ├── CreateFeed.ps1 │ ├── DeleteFeed.ps1 │ ├── DownloadPackage.ps1 │ ├── GetAllFeeds.ps1 │ ├── GetAllPackageSizes.ps1 │ ├── GetFeedDetails.ps1 │ ├── GetLatestPackageVersion.ps1 │ ├── GetListOfPackagesPushedToSpecificEnvironment.ps1 │ ├── GetSpecificPackageVersion.ps1 │ ├── PushPackage.ps1 │ └── SyncPackages.ps1 ├── License │ ├── Get-LicensedTargetStatus.ps1 │ └── GetLicenseDetails.ps1 ├── Lifecycles │ ├── CreateLifecycle.ps1 │ ├── FindLifecyclesWithNoAssociatedReleases.ps1 │ ├── FindLifecyclesWithNoProject.ps1 │ ├── SetRetentionPolicyOfAllLifecycles.ps1 │ ├── UpdateProjectGroupLifecycle.ps1 │ └── UpdateProjectLifecycle.ps1 ├── Machines │ └── README.md ├── ManualInterventions │ └── ApproveOrAbort.ps1 ├── Miscellaneous │ ├── GetMachinesByRolesInCurrentDeployment.ps1 │ └── GetOctopusServerVersion.ps1 ├── OctopusServerNodes │ └── DeleteAllNodes.ps1 ├── Packages │ └── README.md ├── ProjectGroups │ ├── CreateProjectGroup.ps1 │ └── ListProjectsInProjectGroup.ps1 ├── Projects │ ├── ChangeProjectLogo.ps1 │ ├── CheckProjectsForManualIntervention.ps1 │ ├── CloneProject.ps1 │ ├── CopyProjectTriggersToAnotherProject.ps1 │ ├── CreateProject.ps1 │ ├── DeleteProjectByName.ps1 │ ├── DeleteProjectsWithoutDeploymentProcess.ps1 │ ├── DisableAllProjectTriggers.ps1 │ ├── DisableProject.ps1 │ ├── ExportImportProjects.ps1 │ ├── ExportProjects.ps1 │ ├── GetCurrentTargetCountPerProject.ps1 │ ├── GetLastSuccessfulDeploymentPerEnvForAllProjects.ps1 │ ├── ImportProjects.ps1 │ ├── RenameProject.ps1 │ ├── UpdateGuidedFailureMode.ps1 │ ├── UpdateVCSCredsUrl.ps1 │ └── show-all-scheduled-project-triggers.ps1 ├── Releases │ ├── CreateRelease.ps1 │ ├── DeleteReleasesAssociatedWithChannel.ps1 │ ├── DeleteReleasesForProject.ps1 │ ├── GetLastSuccessfulForProjectAndEnvironment.ps1 │ ├── GetLastSuccessfulForProjectAndEnvironmentAndTenant.ps1 │ ├── GetPackageDetailsForRelease.ps1 │ ├── GetReleaseDetails.ps1 │ ├── GetTenantsForReleaseToEnvironment.ps1 │ ├── PromoteReleasesNotInDestination.ps1 │ ├── RedeployLastSuccessfulReleaseForChannel.ps1 │ ├── Release_UpdateReleaseNotes.ps1 │ └── UpdateReleaseVariableSnapshot.ps1 ├── Reports │ ├── DeploymentsByMachineReport.ps1 │ ├── ListPackagesDeployedToMachines.ps1 │ ├── ListTargetsAndTenantsConnectedToEachProject.ps1 │ └── ListTenantedUnhealthyMachines.ps1 ├── Runbooks │ ├── CopyRunbooks.ps1 │ ├── CreateAndPublishRunbookSnapshot.ps1 │ ├── CreateRunbook.ps1 │ ├── CreateScheduledRunbookTrigger.ps1 │ ├── DeleteRunbook.ps1 │ ├── DeleteRunbookSnapshots.ps1 │ ├── PublishRunbook.ps1 │ ├── RunConfigAsCodeRunbook.ps1 │ ├── RunRunbook.ps1 │ ├── RunRunbookWithPromptedVariables.ps1 │ ├── RunRunbookWithPromptedVariablesSpecificMachines.ps1 │ ├── UpdateAllRunbookRetentionSettings.ps1 │ └── UpdateRunbooksToLatestPackages.ps1 ├── ScriptModules │ ├── AddScriptModuleToProject.ps1 │ └── UpdateScriptModule.ps1 ├── Spaces │ ├── AddSpaceWithEnvironments.ps1 │ └── DeleteSpace.ps1 ├── StepTemplates │ ├── DeleteLibraryStepTemplateByName.ps1 │ ├── ExportStepTemplatesToFiles.ps1 │ ├── GetStepTemplateUsage.ps1 │ ├── Initialize-StepTemplateControlTypes.ps1 │ └── UpdateStepTemplateUsage.ps1 ├── Tagsets │ └── CreateTagset.ps1 ├── Targets │ ├── AddRoleToTarget.ps1 │ ├── AddTenantToTarget.ps1 │ ├── ChangeTargetMachinePolicy.ps1 │ ├── CheckForTentacleUpgrades.ps1 │ ├── CheckHealthOfAllEnvironments.ps1 │ ├── CheckHealthOfSpecificTargets.ps1 │ ├── CheckIfMachineHasLatestProjectRelease.ps1 │ ├── CreateAzureWebApp.ps1 │ ├── DeleteMachinesByEnvironment.ps1 │ ├── DeleteMachinesByRole.ps1 │ ├── DeleteTargetByName.ps1 │ ├── DeleteUnavailableMachines.ps1 │ ├── DiscoverTentacle.ps1 │ ├── EnableOrDisableMachines.ps1 │ ├── FindCreatedMachineEvent.ps1 │ ├── FindMachineMatchingUri.ps1 │ ├── FindSHA1Tentacles.ps1 │ ├── FindUnusedTargets.ps1 │ ├── Get-MachineCount.ps1 │ ├── Get-RecentDeploymentsForMachines.ps1 │ ├── GetMachineEnvironments.ps1 │ ├── GetMachinesInCurrentEnvironmentOfSpecificRole.ps1 │ ├── GetTargetsPerSpace.ps1 │ ├── ListMachinesWithUpgradeStatus.ps1 │ ├── ListTargetsMissingSpecificVersion.ps1 │ ├── LockOrUnlockAllTentacleUpgradesInaSpace.ps1 │ ├── RegisterListeningTentacle.ps1 │ ├── RegisterPollingTentacle.ps1 │ ├── RegisterSSHEndpoint.ps1 │ ├── RemoveEnvironmentFromMachines.ps1 │ ├── RemoveRoleFromTarget.ps1 │ ├── RestoreDeletedListeningTentacles.ps1 │ ├── Set-OctopusTargetLockUpgrade.ps1 │ ├── TargetsNeedingCalamariUpgrade.ps1 │ ├── Targets_Delete.ps1 │ ├── UpdateMachineProxy.ps1 │ ├── UpgradeCalamari.ps1 │ └── UpgradeTargets.ps1 ├── Tasks │ ├── ReRunSyncSecurityGroups.ps1 │ ├── ReprioritizeTasks.ps1 │ ├── RunHealthCheck.ps1 │ └── SubmitScriptConsoleTask.ps1 ├── Teams │ ├── AddDomainTeamToOctopusTeam.ps1 │ ├── AddEnvironmentToTeam.ps1 │ ├── AddExternalRoleToTeam.ps1 │ ├── CreateTeam.ps1 │ ├── FindAllTeamsWithSpecifiedPermission.ps1 │ ├── FindTeamsWithUserRole.ps1 │ ├── ListAllTeamsMembershipsAndRoles.ps1 │ ├── RemoveProjectFromTeam.ps1 │ ├── RemoveProjectScopingFromManyTeams.ps1 │ ├── SwitchADGroupToLDAPGroupInOctopusTeams.ps1 │ └── TestActiveDirectoryIntegration.ps1 ├── Tenants │ ├── AddTenantTagToTenant.ps1 │ ├── CloneProjectConnectionsFromExistingTenant.ps1 │ ├── CreateTenant.ps1 │ ├── DuplicateTenantVariablesToAnotherEnvironment.ps1 │ ├── FindTenantProjectDeployments.ps1 │ ├── FindTenantsMatchingTagSetFilter.ps1 │ ├── GetLatestDeploymentForAllTenants.ps1 │ ├── ListTenantsAndProjectTemplateValues.ps1 │ ├── RemoveAllProjectConnectionsToTenant.ps1 │ ├── RemoveEnvironmentfromProjectTenantconnection.ps1 │ ├── RemoveNonExistantProjects.ps1 │ ├── RemoveProjectTenantConnection.ps1 │ ├── RemoveTenantFromCertificates.ps1 │ ├── RemoveTenantFromTriggers.ps1 │ ├── UpdateMultipleTenantVariablesWithSingleValue.ps1 │ ├── UpdateScopedTenantCommonVariable.ps1 │ └── UpdateTenantCommonVariable.ps1 ├── Triggers │ └── CloneTriggersToAnotherSpaceorOctopusInstance.ps1 ├── UserRoles │ ├── CheckUserRoles.ps1 │ └── Copy-UserRole.ps1 ├── Users │ ├── AddAzureActiveDirectoryLoginToUsers.ps1 │ ├── ChangeUsersDomainAccount.ps1 │ ├── CreateAPIKey.ps1 │ ├── CreateUserInvite.ps1 │ ├── DeleteAPIKey.ps1 │ ├── EnableOrDisableUser.ps1 │ ├── Find-UsersWithEditRoles.ps1 │ ├── FindUsersWithUserRole.ps1 │ ├── GetUsersAPIKeyList.ps1 │ ├── ListUsers.ps1 │ ├── ListUsersLastSuccessfulLogin.ps1 │ ├── MatchUsernamesToEmailAddress.ps1 │ ├── SwitchOctopusUsersADLoginToLDAP.ps1 │ └── TestActiveDirectoryIntegration.ps1 ├── Variables │ ├── AddLibraryVariableSetToSelectedProjects.ps1 │ ├── AddNewVariableToLibraryVariableSet.ps1 │ ├── AddOrEditVariablesWithScoping.ps1 │ ├── AddSimpleTenantCommonVariable.ps1 │ ├── AddSimpleTenantProjectVariable.ps1 │ ├── ClearSensitiveVariables.ps1 │ ├── CreateEnvironmentScopedVariables.ps1 │ ├── FindProjectsThatUseALibraryVariableSet.ps1 │ ├── FindVariableSetVariableUsage.ps1 │ ├── FindVariableUsage.ps1 │ ├── FindVariableValueUsage.ps1 │ ├── FindVariablesScopedToMachines.ps1 │ ├── GetTenantVariablesPerProject.ps1 │ ├── GetVariableInProject.ps1 │ ├── GetVariableValueFromADeployment.ps1 │ ├── GetVariablesFromVariableSet.ps1 │ ├── ImportAzureDevopsVariableExportToLibraryVariableSet.ps1 │ ├── ImportVariablesFromFile.ps1 │ ├── MigrateVariableSetVariablesToProject.ps1 │ ├── ModifyOrAddVariableToProject.ps1 │ ├── PreviewVariablesForProjectEnvironment.ps1 │ ├── RemoveLibraryVariableSetFromProject.ps1 │ ├── RemoveMachineScopeFromVariableValue.ps1 │ ├── Test-ReleaseNotes.ps1 │ └── UpdateLibraryVariableSetVariableValue.ps1 └── Workers │ ├── DeleteWorkerDuringDeployment.ps1 │ ├── GetWorkersUsedInTasks.ps1 │ └── RegisterPollingWorker.ps1 ├── bash ├── Feeds │ └── PushPackage.sh ├── Releases │ └── CreateRelease.sh ├── Targets │ └── RegisterSSHEndpoint.sh ├── Tenants │ ├── AddEnvironmentToProjectConnection.sh │ └── UpdateTenantTagSetValue.sh ├── Users │ ├── inviteInstanceUser.sh │ └── inviteOrgUser.sh └── deployments │ └── CreateDeploymentWithPromptedVariables.sh ├── python ├── Accounts │ ├── create-azure-service-principal.py │ └── create-google-cloud-account.py ├── BulkOperations │ └── bulk-add-tenants-to-project.py ├── Certificates │ ├── create-certificate.py │ └── replace-certificate.py ├── Channels │ └── create-channel.py ├── DeploymentProcesses │ ├── add-environment-to-step.py │ ├── create-script-step.py │ ├── get-steps-using-package.py │ └── get-steps-using-role.py ├── Deployments │ ├── cancel-queued-deployments.py │ └── deploy-release.py ├── Environments │ └── create-environments.py ├── Feeds │ ├── change-feed.py │ ├── create-feed.py │ ├── delete-feed.py │ ├── download-package.py │ ├── get-feeds.py │ └── push-package.py ├── Lifecycles │ └── create-lifecycle.py ├── ProjectGroups │ └── create-project-group.py ├── Projects │ ├── create-project.py │ ├── delete-project-by-name.py │ ├── delete-projects-without-processes.py │ ├── disable-project-triggers.py │ ├── enable-or-disable-project.py │ ├── find-projects-using-variable-set.py │ └── import-projects.py ├── Releases │ ├── create-and-deploy-release-with-tenants.py │ ├── create-and-deploy-release.py │ ├── create-release.py │ ├── delete-releases-for-project.py │ └── promote-releases-not-in-destination.py ├── Runbooks │ ├── create-runbook.py │ ├── create-scheduled-runbook-trigger.py │ ├── publish-runbook.py │ └── run-runbook.py ├── Spaces │ ├── add-space-with-environments.py │ └── delete-space.py ├── Tagsets │ └── create-tagset.py ├── Targets │ ├── add-role-to-target.py │ ├── change-target-machine-policy.py │ ├── check-for-tentacle-upgrades.py │ ├── create-azure-web-app.py │ ├── delete-target-by-name.py │ ├── delete-targets-by-role.py │ ├── enable-or-disable-target.py │ ├── find-unused-targets.py │ ├── register-listening-tentacle.py │ ├── register-polling-tentacle.py │ └── upgrade-targets.py ├── Tasks │ ├── find-executing-tasks.py │ └── run-healthcheck.py ├── Teams │ ├── add-environment-to-team.py │ └── remove-project-from-teams.py ├── Tenants │ ├── create-tenants.py │ └── update-tenant-variable-values.py ├── Users │ ├── add-azure-active-directory-login-to-users.py │ ├── create-api-key.py │ ├── find-users-with-edit-roles.py │ ├── find-users-with-role.py │ └── list-users.py └── Variables │ ├── add-library-variableset-to-projects.py │ ├── clear-sensitive-variables.py │ ├── find-variable-usage.py │ ├── find-variable-value-usage.py │ ├── find-variableset-variable-usage.py │ ├── modify-or-add-variable-to-project.py │ └── update-library-variableset-variable-value.py └── ruby └── Deployments ├── Gemfile └── create_release_and_deployment.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | -------------------------------------------------------------------------------- /Deployment-Scripts/Powershell/AzureCSWaitForInstanceSwap.ps1: -------------------------------------------------------------------------------- 1 | # Loop until all instances are running 2 | do { 3 | $ready=0 4 | $total=0 5 | 6 | # query the status of the running instances 7 | $list = (Get-AzureRole -ServiceName #{YourCloudService} -Slot Staging -InstanceDetails).InstanceStatus 8 | 9 | # count the number of ready instances 10 | $list | foreach-object { IF ($_ -eq "ReadyRole") { $ready++ } } 11 | 12 | # count the number in total 13 | $list | foreach-object { $total++ } 14 | 15 | Write-Host "$ready out of $total instances are ready" 16 | 17 | # Sleep for 10 seconds 18 | Start-Sleep -s 10 19 | } 20 | while ($ready -ne $total) 21 | 22 | # Swap staging and production 23 | Move-AzureDeployment -ServiceName #{YourCloudService} 24 | 25 | # Remove the staging slot 26 | Remove-AzureDeployment -ServiceName #{YourCloudService} -Slot Staging -Force 27 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Octopus Deploy and contributors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /Machine-Policy-Scripts/ValidateRolesInMachine.ps1: -------------------------------------------------------------------------------- 1 | #This script will throw an error if at least 1 of the roles in $MandatoryRoles is missing on the machine 2 | 3 | $MandatoryRolesList = "MandatoryRole1","MandatoryRole2" #List of roles that the Machine should have 4 | 5 | function Validate-MandatoryMachineRoles ($MandatoryRoles){ 6 | 7 | $RolesInMachineSplit = $OctopusParameters['Octopus.Machine.Roles'].Split(',') 8 | $MachineName = $($OctopusParameters['Octopus.Machine.Name']) 9 | 10 | $MissingRoles = @() 11 | 12 | foreach($MandatoryRole in $MandatoryRoles){ 13 | If($MandatoryRole -notin $RolesInMachineSplit){ 14 | $MissingRoles += $MandatoryRole 15 | } 16 | } 17 | 18 | If($MissingRoles.Count -ne 0){ 19 | Write-Error "The following mandatory roles were not found in [$MachineName]: $MissingRoles" 20 | } 21 | } 22 | 23 | Validate-MandatoryMachineRoles -MandatoryRoles $MandatoryRolesList 24 | -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Certificates/CreateCertificate.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string pfxFilePath = "path\\to\\pfxfile.pfx"; 13 | string pfxFilePassword = "PFX-file-password"; 14 | string certificateName = "MyCertificate"; 15 | string spaceName = "default"; 16 | 17 | // Create repository object 18 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 19 | var repository = new OctopusRepository(endpoint); 20 | var client = new OctopusClient(endpoint); 21 | 22 | try 23 | { 24 | // Get space 25 | var space = repository.Spaces.FindByName(spaceName); 26 | var repositoryForSpace = client.ForSpace(space); 27 | 28 | // Convert file to base64 29 | string base64Certificate = Convert.ToBase64String(System.IO.File.ReadAllBytes(pfxFilePath)); 30 | 31 | // Create certificate object 32 | Octopus.Client.Model.CertificateResource octopusCertificate = new CertificateResource(certificateName, base64Certificate, pfxFilePassword); 33 | repositoryForSpace.Certificates.Create(octopusCertificate); 34 | } 35 | catch (Exception ex) 36 | { 37 | Console.WriteLine(ex.Message); 38 | return; 39 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Channels/CreateChannel.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | var octopusURL = "https://YourURL"; 10 | var octopusAPIKey = "API-YourAPIKey"; 11 | var spaceName = "Default"; 12 | var projectName = "MyProject"; 13 | var channelName = "NewChannel"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | // Get space 21 | var space = repository.Spaces.FindByName(spaceName); 22 | var spaceRepository = client.ForSpace(space); 23 | 24 | // Get project 25 | var project = spaceRepository.Projects.FindByName(projectName); 26 | 27 | // Create channel object 28 | var channel = new Octopus.Client.Model.ChannelResource(); 29 | channel.Name = channelName; 30 | channel.ProjectId = project.Id; 31 | channel.SpaceId = space.Id; 32 | 33 | spaceRepository.Channels.Create(channel); -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Deployments/CancelQueuedDeployments.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "http://octotemp"; 11 | var octopusAPIKey = "API-KEY"; 12 | string spaceName = "default"; 13 | 14 | // Create repository object 15 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 16 | var repository = new OctopusRepository(endpoint); 17 | var client = new OctopusClient(endpoint); 18 | 19 | try 20 | { 21 | // Get space 22 | var space = repository.Spaces.FindByName(spaceName); 23 | var repositoryForSpace = client.ForSpace(space); 24 | 25 | // Get queued deployemnts 26 | var queuedDeployments = repositoryForSpace.Tasks.FindAll().Where(d => d.State == TaskState.Queued && !d.HasBeenPickedUpByProcessor && d.Name == "Deploy"); 27 | 28 | // Loop through results 29 | foreach (var task in queuedDeployments) 30 | { 31 | // Cancel deployment 32 | repositoryForSpace.Tasks.Cancel(task); 33 | } 34 | } 35 | catch (Exception ex) 36 | { 37 | Console.WriteLine(ex.Message); 38 | return; 39 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Deployments/RetrievePagedListOfDeploymentsToEnvironment.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | var octopusURL = "https://youroctourl"; 10 | var octopusAPIKey = "API-YOURAPIKEY"; 11 | 12 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 13 | var repository = new OctopusRepository(endpoint); 14 | 15 | var spaceName = "Default"; 16 | var environmentName = "Dev"; 17 | 18 | try 19 | { 20 | // Get the space to work in 21 | var space = repository.Spaces.FindByName(spaceName); 22 | Console.WriteLine($"Using Space named {space.Name} with id {space.Id}"); 23 | 24 | // Create space specific repository 25 | var repositoryForSpace = repository.ForSpace(space); 26 | 27 | // Get environment 28 | var environment = repositoryForSpace.Environments.FindByName(environmentName); 29 | 30 | // Get paged list of deployments for that environment 31 | var deployments = new List(); 32 | repositoryForSpace.Deployments.Paginate(null, new[] { environment.Id }, page => 33 | { 34 | deployments.AddRange(page.Items); 35 | return true; 36 | }); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine(ex.Message); 41 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Feeds/ChangeFeed.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | 13 | string spaceName = "Default"; 14 | string feedName = "nuget.org"; 15 | string newFeedName = "nuget.org feed"; 16 | 17 | // Create repository object 18 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 19 | var repository = new OctopusRepository(endpoint); 20 | var client = new OctopusClient(endpoint); 21 | 22 | try 23 | { 24 | // Get space 25 | var space = repository.Spaces.FindByName(spaceName); 26 | var repositoryForSpace = client.ForSpace(space); 27 | 28 | // Get Feed 29 | var feed = repositoryForSpace.Feeds.FindByName(feedName); 30 | 31 | // Change feed name 32 | feed.Name = newFeedName; 33 | 34 | // Update feed 35 | repositoryForSpace.Feeds.Modify(feed); 36 | } 37 | catch (Exception ex) 38 | { 39 | Console.WriteLine(ex.Message); 40 | return; 41 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Feeds/DeleteFeed.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | 13 | string spaceName = "Default"; 14 | string feedName = "nuget to delete"; 15 | 16 | // Create repository object 17 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 18 | var repository = new OctopusRepository(endpoint); 19 | var client = new OctopusClient(endpoint); 20 | 21 | try 22 | { 23 | // Get space 24 | var space = repository.Spaces.FindByName(spaceName); 25 | var repositoryForSpace = client.ForSpace(space); 26 | 27 | // Get Feed 28 | var feed = repositoryForSpace.Feeds.FindByName(feedName); 29 | 30 | // Delete feed 31 | repositoryForSpace.Feeds.Delete(feed); 32 | } 33 | catch (Exception ex) 34 | { 35 | Console.WriteLine(ex.Message); 36 | return; 37 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Feeds/GetAllFeeds.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | 13 | string spaceName = "Default"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | try 21 | { 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var repositoryForSpace = client.ForSpace(space); 25 | 26 | // Get All feeds 27 | var feeds = repositoryForSpace.Feeds.FindAll(); 28 | 29 | foreach (var feed in feeds) 30 | { 31 | Console.WriteLine("Feed Id: {0}", feed.Id); 32 | Console.WriteLine("Feed Name: {0}", feed.Name); 33 | Console.WriteLine("Feed Type: {0}", feed.FeedType); 34 | Console.WriteLine(); 35 | } 36 | } 37 | catch (Exception ex) 38 | { 39 | Console.WriteLine(ex.Message); 40 | return; 41 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Feeds/PushPackage.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | 10 | // Declare working varibles 11 | var octopusURL = "https://youroctourl"; 12 | var octopusAPIKey = "API-APIKEY"; 13 | var spaceName = "default"; 14 | string packageFile = "path\\to\\file"; 15 | System.IO.FileStream fileStream = null; 16 | 17 | // Create repository object 18 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 19 | var repository = new OctopusRepository(endpoint); 20 | var client = new OctopusClient(endpoint); 21 | 22 | try 23 | { 24 | // Get space 25 | var space = repository.Spaces.FindByName(spaceName); 26 | var repositoryForSpace = client.ForSpace(space); 27 | 28 | // Open file stream 29 | fileStream = new System.IO.FileStream(packageFile, System.IO.FileMode.Open); 30 | 31 | // Push package 32 | repositoryForSpace.BuiltInPackageRepository.PushPackage(packageFile, fileStream); 33 | } 34 | catch (Exception ex) 35 | { 36 | Console.WriteLine(ex.Message); 37 | Console.ReadLine(); 38 | return; 39 | } 40 | finally 41 | { 42 | if (fileStream != null) 43 | { 44 | fileStream.Close(); 45 | } 46 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Lifecycles/CreateLifecycle.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | using System; 9 | using System.Linq; 10 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 11 | 12 | var octopusURL = "https://YourURL"; 13 | var octopusAPIKey = "API-YourAPIKey"; 14 | var spaceName = "Default"; 15 | var lifecycleName = "MyLifecycle"; 16 | 17 | // Create repository object 18 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 19 | var repository = new OctopusRepository(endpoint); 20 | var client = new OctopusClient(endpoint); 21 | 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var spaceRepository = client.ForSpace(space); 25 | 26 | if (null == spaceRepository.Lifecycles.FindByName(lifecycleName)) 27 | { 28 | // Create new lifecycle 29 | var lifecycle = new Octopus.Client.Model.LifecycleResource(); 30 | lifecycle.Name = lifecycleName; 31 | spaceRepository.Lifecycles.Create(lifecycle); 32 | } 33 | else 34 | { 35 | Console.Write(string.Format("{0} already exists.", lifecycleName)); 36 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Machines/README.md: -------------------------------------------------------------------------------- 1 | # Machines 2 | 3 | You can find scripts related to machines under the [Targets](../Targets) folder. 4 | -------------------------------------------------------------------------------- /Octopus.Client/Csharp/ProjectGroups/CreateProjectGroup.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | var octopusURL = "https://your.octopus.app"; 10 | var octopusAPIKey = "API-YOUR-KEY"; 11 | var spaceName = "Default"; 12 | var projectGroupName = "MyProjectGroup"; 13 | var projectGroupDescription = "My Description"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | // Get space 21 | var space = repository.Spaces.FindByName(spaceName); 22 | var spaceRepository = client.ForSpace(space); 23 | 24 | // Create project group object 25 | var projectGroup = new Octopus.Client.Model.ProjectGroupResource(); 26 | projectGroup.Description = projectGroupDescription; 27 | projectGroup.Name = projectGroupName; 28 | projectGroup.EnvironmentIds = null; 29 | projectGroup.RetentionPolicyId = null; 30 | 31 | // Create the project group 32 | spaceRepository.ProjectGroups.Create(projectGroup); -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Projects/CloneProject.cs: -------------------------------------------------------------------------------- 1 | var client = new OctopusClient(new OctopusServerEndpoint(octoUrl, apiKey)); 2 | var repo = new OctopusRepository(client); 3 | 4 | var project = repo.Projects.FindByName("MyOriginalProject"); 5 | 6 | var newProject = new ProjectResource 7 | { 8 | Name = "MyClonedProject", 9 | Description = "Cloned copy", 10 | ProjectGroupId = project.ProjectGroupId, 11 | LifecycleId = project.LifecycleId 12 | }; 13 | client.Post("~/api/projects?clone=" + project.Id, newProject); -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Projects/CreateProject.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string spaceName = "default"; 13 | string projectName = "MyProject"; 14 | string projectGroupName = "Default project group"; 15 | string lifecycleName = "Default lifecycle"; 16 | 17 | // Create repository object 18 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 19 | var repository = new OctopusRepository(endpoint); 20 | var client = new OctopusClient(endpoint); 21 | 22 | try 23 | { 24 | // Get space 25 | var space = repository.Spaces.FindByName(spaceName); 26 | var repositoryForSpace = client.ForSpace(space); 27 | 28 | // Get project group 29 | var projectGroup = repositoryForSpace.ProjectGroups.FindByName(projectGroupName); 30 | 31 | // Get lifecycle 32 | var lifecycle = repositoryForSpace.Lifecycles.FindByName(lifecycleName); 33 | 34 | // Create project 35 | var project = repositoryForSpace.Projects.CreateOrModify(projectName, projectGroup, lifecycle); 36 | project.Save(); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine(ex.Message); 41 | return; 42 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Projects/DeleteProjectByName.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | var spaceName = "default"; 13 | string projectName = "MyProject"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | try 21 | { 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var repositoryForSpace = client.ForSpace(space); 25 | 26 | // Get project 27 | var project = repositoryForSpace.Projects.FindByName(projectName); 28 | 29 | // Delete project 30 | repositoryForSpace.Projects.Delete(project); 31 | } 32 | catch (Exception ex) 33 | { 34 | Console.WriteLine(ex.Message); 35 | return; 36 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Projects/DisableProjectTriggers.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | var spaceName = "default"; 13 | string projectName = "MyProject"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | try 21 | { 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var repositoryForSpace = client.ForSpace(space); 25 | 26 | // Get project 27 | var project = repositoryForSpace.Projects.FindByName(projectName); 28 | 29 | var projectTriggers = repositoryForSpace.Projects.GetAllTriggers(project); 30 | 31 | foreach (var projectTrigger in projectTriggers) 32 | { 33 | // Disable trigger 34 | projectTrigger.IsDisabled = true; 35 | repositoryForSpace.ProjectTriggers.Modify(projectTrigger); 36 | } 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine(ex.Message); 41 | return; 42 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Releases/DeleteReleasesForProject.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string spaceName = "default"; 13 | string projectName = "MyProject"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | try 21 | { 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var repositoryForSpace = client.ForSpace(space); 25 | 26 | // Get project 27 | var project = repositoryForSpace.Projects.FindByName(projectName); 28 | 29 | // Get releases 30 | var releases = repositoryForSpace.Releases.FindMany(p => p.ProjectId == project.Id); 31 | 32 | // Loop through results 33 | foreach (var release in releases) 34 | { 35 | // Delete release 36 | repositoryForSpace.Releases.Delete(release); 37 | } 38 | } 39 | catch (Exception ex) 40 | { 41 | Console.WriteLine(ex.Message); 42 | return; 43 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Spaces/DeleteSpace.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | var OctopusURL = "https://youroctourl"; 10 | var OctopusAPIKey = "API-YOURAPIKEY"; 11 | 12 | var endpoint = new OctopusServerEndpoint(OctopusURL, OctopusAPIKey); 13 | var repository = new OctopusRepository(endpoint); 14 | 15 | var spaceName = "New Space"; 16 | 17 | try 18 | { 19 | Console.WriteLine($"Getting space '{spaceName}'."); 20 | var space = repository.Spaces.FindByName(spaceName); 21 | 22 | if (space == null) 23 | { 24 | Console.WriteLine($"Could not find space '{spaceName}'."); 25 | return; 26 | } 27 | 28 | Console.WriteLine("Stopping task queue."); 29 | space.TaskQueueStopped = true; 30 | 31 | repository.Spaces.Modify(space); 32 | 33 | Console.WriteLine("Deleting space"); 34 | repository.Spaces.Delete(space); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine(ex.Message); 39 | return; 40 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Targets/AddRoleToTarget.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string spaceName = "default"; 13 | string machineName = "MyMachine"; 14 | string roleName = "testrole"; 15 | 16 | // Create repository object 17 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 18 | var repository = new OctopusRepository(endpoint); 19 | var client = new OctopusClient(endpoint); 20 | 21 | try 22 | { 23 | // Get space 24 | var space = repository.Spaces.FindByName(spaceName); 25 | var repositoryForSpace = client.ForSpace(space); 26 | 27 | // Get machine 28 | var machine = repositoryForSpace.Machines.FindByName(machineName); 29 | 30 | // Add role 31 | machine.Roles.Add(roleName); 32 | repositoryForSpace.Machines.Modify(machine); 33 | } 34 | catch (Exception ex) 35 | { 36 | Console.WriteLine(ex.Message); 37 | return; 38 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Targets/ChangeTargetMachinePolicy.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string spaceName = "default"; 13 | string machineName = "MyMachine"; 14 | string machinePolicyName = "TestPolicy"; 15 | 16 | // Create repository object 17 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 18 | var repository = new OctopusRepository(endpoint); 19 | var client = new OctopusClient(endpoint); 20 | 21 | try 22 | { 23 | // Get space 24 | var space = repository.Spaces.FindByName(spaceName); 25 | var repositoryForSpace = client.ForSpace(space); 26 | 27 | // Get machine list 28 | var machine = repositoryForSpace.Machines.FindByName(machineName); 29 | 30 | // Get machine policy 31 | var machinePolicy = repositoryForSpace.MachinePolicies.FindByName(machinePolicyName); 32 | 33 | // Change machine policy for machine 34 | machine.MachinePolicyId = machinePolicy.Id; 35 | repositoryForSpace.Machines.Modify(machine); 36 | } 37 | catch (Exception ex) 38 | { 39 | Console.WriteLine(ex.Message); 40 | return; 41 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Targets/DeleteMachinesByRole.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://your.octopus.app"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string spaceName = "default"; 13 | string role = "MyRole"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | try 21 | { 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var repositoryForSpace = client.ForSpace(space); 25 | 26 | // Get machine list 27 | var machines = repositoryForSpace.Machines.FindAll().Where(r => r.Roles.Contains(role)); 28 | 29 | // Loop through list 30 | foreach (var machine in machines) 31 | { 32 | // Delete machine 33 | repositoryForSpace.Machines.Delete(machine); 34 | } 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine(ex.Message); 39 | return; 40 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Targets/DeleteTargetByName.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string spaceName = "default"; 13 | string machineName = "MachineName"; 14 | 15 | // Create repository object 16 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 17 | var repository = new OctopusRepository(endpoint); 18 | var client = new OctopusClient(endpoint); 19 | 20 | try 21 | { 22 | // Get space 23 | var space = repository.Spaces.FindByName(spaceName); 24 | var repositoryForSpace = client.ForSpace(space); 25 | 26 | // Get machine 27 | var machine = repositoryForSpace.Machines.FindByName(machineName); 28 | 29 | // Delete machine 30 | repositoryForSpace.Machines.Delete(machine); 31 | } 32 | catch (Exception ex) 33 | { 34 | Console.WriteLine(ex.Message); 35 | return; 36 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Targets/EnableOrDisableAMachine.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | var spaceName = "default"; 13 | var machineName = "MyMachine"; 14 | bool enabled = false; 15 | 16 | // Create repository object 17 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 18 | var repository = new OctopusRepository(endpoint); 19 | var client = new OctopusClient(endpoint); 20 | 21 | try 22 | { 23 | // Get space 24 | var space = repository.Spaces.FindByName(spaceName); 25 | var repositoryForSpace = client.ForSpace(space); 26 | 27 | // Get machine 28 | var machine = repositoryForSpace.Machines.FindByName(machineName); 29 | 30 | // Enable/disable machine 31 | machine.IsDisabled = !enabled; 32 | 33 | //update machine 34 | repositoryForSpace.Machines.Modify(machine); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine(ex.Message); 39 | return; 40 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Users/CreateAPIKey.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | 3 | // Reference Octopus.Client 4 | //#r "path\to\Octopus.Client.dll" 5 | 6 | using Octopus.Client; 7 | using Octopus.Client.Model; 8 | 9 | // Declare working varibles 10 | var octopusURL = "https://youroctourl"; 11 | var octopusAPIKey = "API-YOURAPIKEY"; 12 | string apiKeyPurpose = "Key used with C# application"; 13 | 14 | // Create repository object 15 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 16 | var repository = new OctopusRepository(endpoint); 17 | 18 | try 19 | { 20 | // Get Current user 21 | var user = repository.Users.GetCurrent(); 22 | 23 | // Create API Key for user 24 | var apiKeyResponse = repository.Users.CreateApiKey(user, apiKeyPurpose); 25 | 26 | // Return the API Key 27 | Console.WriteLine("API Key created: {0}", apiKeyResponse.ApiKey); 28 | } 29 | catch (Exception ex) 30 | { 31 | Console.WriteLine(ex.Message); 32 | return; 33 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Variables/AddLibraryVariableSetToSelectedProjects.cs: -------------------------------------------------------------------------------- 1 | // If using .net Core, be sure to add the NuGet package of System.Security.Permissions 2 | //#r "path\to\Octopus.Client.dll" 3 | 4 | using Octopus.Client; 5 | using Octopus.Client.Model; 6 | 7 | // Declare working varibles 8 | var octopusURL = "https://youroctourl"; 9 | var octopusAPIKey = "API-YOURAPIKEY"; 10 | string spaceName = "default"; 11 | string projectName = "MyProject"; 12 | string librarySetName = "MyLibrarySet"; 13 | 14 | // Create repository object 15 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 16 | var repository = new OctopusRepository(endpoint); 17 | var client = new OctopusClient(endpoint); 18 | 19 | try 20 | { 21 | // Get space 22 | var space = repository.Spaces.FindByName(spaceName); 23 | var repositoryForSpace = client.ForSpace(space); 24 | 25 | // Get project 26 | var project = repositoryForSpace.Projects.FindByName(projectName); 27 | 28 | // Get libarary set 29 | var librarySet = repositoryForSpace.LibraryVariableSets.FindByName(librarySetName); 30 | 31 | // Include library set to project 32 | project.IncludedLibraryVariableSetIds.Add(librarySet.Id); 33 | 34 | // Update project 35 | repositoryForSpace.Projects.Modify(project); 36 | } 37 | catch (Exception ex) 38 | { 39 | Console.WriteLine(ex.Message); 40 | return; 41 | } -------------------------------------------------------------------------------- /Octopus.Client/Csharp/Variables/UpdateLibraryVariableSetVariableValue.cs: -------------------------------------------------------------------------------- 1 | #r "path\to\Octopus.Client.dll" 2 | 3 | using Octopus.Client; 4 | using Octopus.Client.Model; 5 | using System.Linq; 6 | 7 | var octopusURL = "https://your.octopusdemos.app"; 8 | var octopusAPIKey = "API-YOURKEY"; 9 | 10 | // Create repository object 11 | var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); 12 | var repository = new OctopusRepository(endpoint); 13 | var client = new OctopusClient(endpoint); 14 | var spaceName = "Default"; 15 | string libraryVariableSetName = "MyLibraryVariableSet"; 16 | string variableName = "MyVariable"; 17 | string variableValue = "MyValue"; 18 | 19 | var space = repository.Spaces.FindByName(spaceName); 20 | var repositoryForSpace = client.ForSpace(space); 21 | 22 | Console.WriteLine(string.Format("Looking for library variable set '{0}'", libraryVariableSetName)); 23 | 24 | var librarySet = repositoryForSpace.LibraryVariableSets.FindByName(libraryVariableSetName); 25 | 26 | if (null == librarySet) 27 | { 28 | throw new Exception(string.Format("Library variable not found with name '{0}'", libraryVariableSetName)); 29 | } 30 | 31 | // Get the variable set 32 | var variableSet = repositoryForSpace.VariableSets.Get(librarySet.VariableSetId); 33 | 34 | // Update the variable 35 | variableSet.Variables.FirstOrDefault(v => v.Name == variableName).Value = variableValue; 36 | repositoryForSpace.VariableSets.Modify(variableSet); -------------------------------------------------------------------------------- /Octopus.Client/LINQPad/CreateLibraryVariableSetAndAddToAllProjects.linq: -------------------------------------------------------------------------------- 1 | 2 | Octopus.Client 3 | 4 | 5 | var octopusUrl = "http://octopus.url"; 6 | var apiKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXX"; 7 | 8 | var octopusServer = new Octopus.Client.OctopusServerEndpoint(octopusUrl, apiKey); 9 | var repo = new Octopus.Client.OctopusRepository(octopusServer); 10 | 11 | var newLibraryVariableSet = new Octopus.Client.Model.LibraryVariableSetResource(); 12 | newLibraryVariableSet.Name = "Name"; 13 | newLibraryVariableSet.Description = "Description"; 14 | var skipDeltaCompressionVariableSet = repo.LibraryVariableSets.Create(newLibraryVariableSet); 15 | 16 | var newVariableSet = repo.VariableSets.Get(skipDeltaCompressionVariableSet.VariableSetId); 17 | newVariableSet.Variables.Add(new Octopus.Client.Model.VariableResource { Name = "Variable Name", Value = "value" }); 18 | 19 | var variableSet = repo.VariableSets.Modify(newVariableSet); 20 | 21 | var projects = repo.Projects.GetAll(); 22 | foreach(var projectRef in projects) 23 | { 24 | var project = repo.Projects.Get(projectRef.Id); 25 | project.IncludedLibraryVariableSetIds.Add(skipDeltaCompressionVariableSet.Id); 26 | repo.Projects.Modify(project); 27 | } -------------------------------------------------------------------------------- /Octopus.Client/LINQPad/WorkInADifferentSpace.linq: -------------------------------------------------------------------------------- 1 | void Main() 2 | { 3 | var apiKey = "API-YOUR_KEY"; 4 | 5 | var octopusServer = new Octopus.Client.OctopusServerEndpoint("http://your.octopus.instance", apiKey); 6 | var repo = new Octopus.Client.OctopusRepository(octopusServer); 7 | var spaceToWorkIn = repo.Spaces.FindByName("Another Space"); 8 | var spaceRepo = repo.ForSpace(spaceToWorkIn); 9 | 10 | var projectsInThisSpace = spaceRepo.Projects.GetAll(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Accounts/findAzureAccountUsage.ps1: -------------------------------------------------------------------------------- 1 | #This script will look for the usage of a specific Azure Account in all projects and print the results 2 | 3 | ##CONFIG## 4 | 5 | $apikey = 'API-xxxx' # Get this from your profile 6 | 7 | $octopusURI = 'http://YourOctopusServer' # Your Octopus Server address 8 | 9 | $AccountName = "Your Account Name" #Name of the account that you want to find 10 | 11 | ##PROCESS## 12 | 13 | Add-Type -Path 'Octopus.Client.dll' 14 | 15 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 16 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 17 | 18 | $AllProjects = $Repository.Projects.FindAll() 19 | 20 | $Account = $Repository.Accounts.FindByName($AccountName) 21 | 22 | foreach($project in $AllProjects){ 23 | $deploymentProcess = $Repository.DeploymentProcesses.Get($project.deploymentprocessid) 24 | 25 | foreach($step in $deploymentProcess.steps){ 26 | foreach ($action in $step.actions){ 27 | if($action.Properties['Octopus.Action.Azure.AccountId'].value -eq $Account.Id){ 28 | Write-Output "Project - [$($project.name)]" 29 | Write-Output "`t- Account [$($account.name)] is being used in the step [$($step.name)]" 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Certificates/DeleteDuplicateCertificates.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load Octopus Client assembly 4 | Add-Type -Path 'path\to\Octopus.Client.dll' 5 | 6 | # Create endpoint and client 7 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint("http://OctopusServer/", "API-KEY") 8 | $client = New-Object Octopus.Client.OctopusClient($endpoint) 9 | 10 | # Get default repository and get space by name 11 | #$repository = $client.ForSystem() 12 | #$space = $repository.Spaces.FindByName("Second") 13 | 14 | # Get space specific repository and get all projects in space 15 | #$repo = $client.ForSpace($space) 16 | 17 | $certificates = $client.Repository.Certificates.GetAll() 18 | 19 | $certsToKeep = New-Object Collections.Generic.List[string] 20 | 21 | # Will remove any duplicate certificates from Octopus based on SerialNumber. Delete function is commented out for a dry run. 22 | 23 | foreach ($cert in $certificates) { 24 | 25 | if ($certsToKeep -contains $cert.SerialNumber) { 26 | Write-host "Deleting:" $cert.id 27 | #$client.Repository.Certificates.Delete($cert) # Run this script before you enable the delete to confirm that you are Keeping & Deleting the correct certificates. 28 | } 29 | else { 30 | $certsToKeep.Add($cert.SerialNumber) 31 | Write-Host "Keeping:" $cert.id 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Channels/CreateChannel.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load Octopus Client assembly 4 | Add-Type -Path 'path\to\Octopus.Client.dll' 5 | 6 | $octopusURL = "https://YourUrl" 7 | $octopusAPIKey = "API-YourAPIKey" 8 | $spaceName = "Default" 9 | $projectName = "MyProject" 10 | $channelName = "NewChannel" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint($octopusURL, $octopusAPIKey) 13 | $repository = New-Object Octopus.Client.OctopusRepository($endpoint) 14 | $client = New-Object Octopus.Client.OctopusClient($endpoint) 15 | 16 | # Get space 17 | $space = $repository.Spaces.FindByName($spaceName) 18 | $repositoryForSpace = $client.ForSpace($space) 19 | 20 | # Get project 21 | $project = $repositoryForSpace.Projects.FindByName($projectName) 22 | 23 | # Createw new channel object 24 | $channel = New-Object Octopus.Client.Model.ChannelResource 25 | $channel.Name = $channelName 26 | $channel.ProjectId = $project.Id 27 | $channel.SpaceId = $space.Id 28 | 29 | # Add channel 30 | $repositoryForSpace.Channels.Create($channel) 31 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/DeploymentProcesses/ChangePackageFeedForProjects.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-XXXXXXXXXXXXXXXXXXXXXX' # Get this from your profile 6 | $octopusURI = 'https://octopus.url' # Your server address 7 | $projectSearchString = "FOO" # Common string contained in projects to change 8 | 9 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 10 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 11 | 12 | $repository.Projects.FindMany({Param($p) $p.Name.Contains($projectSearchString)}) | % { 13 | $process = $repository.DeploymentProcesses.Get($_.DeploymentProcessId) 14 | $process.Steps | % { 15 | $_.Actions | % { 16 | if ($_.ActionType -eq "Octopus.TentaclePackage") 17 | { 18 | Write-Output "Setting feed for step $($_.Name) to the built-in package repository" 19 | $_.Properties["Octopus.Action.Package.FeedId"] = "feeds-builtin" 20 | } 21 | } 22 | } 23 | $repository.DeploymentProcesses.Modify($process) 24 | } 25 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/DeploymentProcesses/GetStepsUsingPackage.ps1: -------------------------------------------------------------------------------- 1 | Add-Type -Path "path\to\Octopus.Client.dll" 2 | 3 | # Octopus variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $spaceName = "default" 7 | $packageId = "PackageId" 8 | 9 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 10 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 11 | $client = New-Object Octopus.Client.OctopusClient $endpoint 12 | 13 | # Get space 14 | $space = $repository.Spaces.FindByName($spaceName) 15 | $repositoryForSpace = $client.ForSpace($space) 16 | 17 | $projectList = $repositoryForSpace.Projects.GetAll() 18 | 19 | "Looking for steps with the package $($packageId) in them..." 20 | 21 | foreach ($project in $projectList) { 22 | 23 | $deploymentProcess = $repositoryForSpace.DeploymentProcesses.Get($project) 24 | 25 | # Loop through steps 26 | foreach ($step in $deploymentProcess.Steps) { 27 | $packages = $step.Actions.Packages 28 | if ($null -ne $packages) { 29 | $packageIds = $packages | Where-Object { $_.PackageId -eq $packageId } 30 | if ($packageIds.Count -gt 0) { 31 | Write-Host "Step: $($step.Name) of project: $($project.Name) is using package '$packageId'." 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/DeploymentProcesses/GetStepsUsingRole.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path "path\to\Octopus.Client.dll" 4 | 5 | # Octopus variables 6 | $octopusURL = "https://youroctourl" 7 | $octopusAPIKey = "API-YOURAPIKEY" 8 | $spaceName = "default" 9 | $roleName = "My role" 10 | 11 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 12 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 13 | $client = New-Object Octopus.Client.OctopusClient $endpoint 14 | 15 | # Get space 16 | $space = $repository.Spaces.FindByName($spaceName) 17 | $repositoryForSpace = $client.ForSpace($space) 18 | 19 | $projectList = $repositoryForSpace.Projects.GetAll() 20 | 21 | "Looking for steps with the role $($roleName) in them..." 22 | 23 | foreach($project in $projectList) 24 | { 25 | # Get deployment process 26 | $deploymentProcess = $repositoryForSpace.DeploymentProcesses.Get($project) 27 | 28 | # Loop through steps 29 | foreach ($step in $deploymentProcess.Steps) 30 | { 31 | if($step.properties.'Octopus.Action.TargetRoles' -and ($step.properties.'Octopus.Action.TargetRoles'.Value.Split(',') -Icontains $roleName )) 32 | { 33 | "Step [$($step.Name)] from project [$($project.Name)] is using the role [$($roleName )]" 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/DeploymentProcesses/RemoveDeploymentProcessStep.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-KEY' # Get this from your profile 6 | $octopusURI = 'https://localhost' # Your server address 7 | $projectNames = @('') # Name of the Project(s) in which you want to add the step, leave empty string for ALL 8 | $stepName = '' # The name of the step you want to remove 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | 13 | foreach ($name in $projectNames) { 14 | if (![string]::IsNullOrEmpty($projectNames)) { 15 | $projects = $repository.Projects.FindByName($name) 16 | } 17 | else { 18 | $projects = $repository.Projects.GetAll() 19 | } 20 | 21 | foreach ($project in $projects) { 22 | $process = $repository.DeploymentProcesses.Get($project.DeploymentProcessId) 23 | $IndexOfStep = $process.Steps.Name.IndexOf($stepName) 24 | if($IndexOfStep -ne -1) { 25 | $process.Steps.RemoveAt($IndexOfStep) 26 | 27 | } 28 | else { 29 | Write-Host "'$stepName' does not exist in this project" -ForegroundColor Green 30 | } 31 | $repository.DeploymentProcesses.Modify($process) 32 | } 33 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/DeploymentProcesses/RemoveRoleFromAllSteps.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-MCPLE1AQM2VKTRFDLIBMORQHBXA' # Get this from your profile 6 | $octopusURI = 'http://localhost' # Your server address 7 | 8 | $projectName = "Demo Project" # Name of your project 9 | $roleToRemove = "Demo-role" # Role to remove (case sensitive) 10 | 11 | $endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 12 | $repository = new-object Octopus.Client.OctopusRepository $endpoint 13 | 14 | $project = $repository.Projects.FindByName($projectName) 15 | 16 | $deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessId) 17 | 18 | foreach ($step in $deploymentProcess.Steps) 19 | { 20 | [System.Collections.ArrayList]$roles = $step.Properties.'Octopus.Action.TargetRoles'.Split(",") 21 | If($roles -contains $roleToRemove){ 22 | $roles.Remove($roleToRemove) 23 | $step.Properties.'Octopus.Action.TargetRoles' = $roles -join "," 24 | } 25 | } 26 | 27 | $repository.DeploymentProcesses.Modify($deploymentProcess) 28 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/DeploymentProcesses/ScopeRoleToStep.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-MCPLE1AQM2VKTRFDLIBMORQHBXA' # Get this from your profile 6 | $octopusURI = 'http://localhost' # Your server address 7 | 8 | $projectName = "Demo project" # The name of your project 9 | $roleName = "demo-role" # The role this step will be scoped to 10 | 11 | $endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 12 | $repository = new-object Octopus.Client.OctopusRepository $endpoint 13 | 14 | $project = $repository.Projects.FindByName($projectName) 15 | 16 | $deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessId) 17 | 18 | foreach ($step in $deploymentProcess.Steps) 19 | { 20 | $step.Properties.'Octopus.Action.TargetRoles' = $roleName 21 | } 22 | $repository.DeploymentProcesses.Modify($deploymentProcess) 23 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Deployments/CancelQueued.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | 4 | # Load octopus.client assembly 5 | Add-Type -Path "path\to\Octopus.Client.dll" 6 | 7 | # Octopus variables 8 | $octopusURL = "https://youroctourl" 9 | $octopusAPIKey = "API-YOURAPIKEY" 10 | $spaceName = "default" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get tasks 23 | $queuedDeployments = $repositoryForSpace.Tasks.FindAll() | Where-Object {$_.State -eq "Queued" -and $_.HasBeenPickedUpByProcessor -eq $false -and $_.Name -eq "Deploy"} 24 | 25 | # Loop through results 26 | foreach ($task in $queuedDeployments) 27 | { 28 | $repositoryForSpace.Tasks.Cancel($task) 29 | } 30 | } 31 | catch 32 | { 33 | Write-Host $_.Exception.Message 34 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Deployments/DeployReleaseToTenant.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-xxx' # Get this from your profile 6 | $octopusURI = 'http://localhost' # Your Octopus Server address 7 | 8 | $releaseId = "Releases-1" # Get this from /api/releases 9 | $environmentId = "Environments-1" # Get this from /api/environments 10 | $tenantId = "Tenants-1" # Get this from /api/tenants 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | 15 | $release = $repository.Releases.Get($releaseId); 16 | $deployment = new-object Octopus.Client.Model.DeploymentResource 17 | $deployment.ReleaseId = $release.Id 18 | $deployment.ProjectId = $release.ProjectId 19 | $deployment.EnvironmentId = $environmentId 20 | $deployment.TenantId = $tenantId 21 | 22 | $repository.Deployments.Create($deployment) 23 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Deployments/RetrievePagedListOfDeploymentsToEnvironment.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "Octopus.Client.dll" 3 | $octopusURL = "https://your.octopus.app" 4 | $octopusAPIKey = "API-KEY" 5 | 6 | $spaceName = "Default" 7 | $environmentName = "Development" 8 | 9 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 10 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 11 | 12 | 13 | # Get space id 14 | $space = $repository.Spaces.FindByName($spaceName) 15 | Write-Host "Using Space named $($space.Name) with id $($space.Id)" 16 | 17 | # Create space specific repository 18 | $repositoryForSpace = [Octopus.Client.OctopusRepositoryExtensions]::ForSpace($repository, $space) 19 | 20 | # Get environment 21 | $environment = $repositoryForSpace.Environments.FindByName($environmentName) 22 | 23 | # Get deployments to environment 24 | $projects = @() 25 | $environments = @($environment.Id) 26 | $deployments = New-Object System.Collections.Generic.List[System.Object] 27 | 28 | $repositoryForSpace.Deployments.Paginate($projects, $environments, {param($page) 29 | Write-Host "Found $($page.Items.Count) deployments."; 30 | $deployments.AddRange($page.Items); 31 | return $True; 32 | }) 33 | 34 | Write-Host "Retrieved $($deployments.Count) deployments to environment $($environmentName)" 35 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Events/FindByDate.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "c:\octopus.client\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://your.octopus.app" 8 | $octopusAPIKey = "API-YOURKEY" 9 | $spaceName = "default" 10 | $eventDate = "9/9/2020" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get events 23 | $events = $repositoryForSpace.Events.FindAll() | Where-Object {($_.Occurred -ge [datetime]$eventDate) -and ($_.Occurred -le ([datetime]$eventDate).AddDays(1).AddSeconds(-1))} 24 | 25 | # Display events 26 | foreach ($event in $events) 27 | { 28 | $event 29 | } 30 | } 31 | catch 32 | { 33 | Write-Host $_.Exception.Message 34 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Feeds/ChangeFeed.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path "C:\Octo\Octopus.Client.dll" 4 | 5 | # Octopus variables 6 | $octopusURL = "https://youroctourl" 7 | $octopusAPIKey = "API-YOURAPIKEY" 8 | 9 | $spaceName = "default" 10 | $feedName = "nuget.org" 11 | $newFeedName = "nuget.org feed" 12 | 13 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 14 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 15 | 16 | try 17 | { 18 | # Get space id 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | Write-Host "Using Space named $($space.Name) with id $($space.Id)" 21 | 22 | # Create space specific repository 23 | $repositoryForSpace = [Octopus.Client.OctopusRepositoryExtensions]::ForSpace($repository, $space) 24 | 25 | # Get feed 26 | $feed = $repositoryForSpace.Feeds.FindByName($feedName) 27 | 28 | # Change feed name 29 | $feed.Name = $newFeedName 30 | 31 | # Update feed 32 | $repositoryForSpace.Feeds.Modify($feed) | Out-Null 33 | } 34 | catch 35 | { 36 | Write-Host $_.Exception.Message 37 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Feeds/DeleteFeed.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path "C:\Octo\Octopus.Client.dll" 4 | 5 | # Octopus variables 6 | $octopusURL = "https://youroctourl" 7 | $octopusAPIKey = "API-YOURAPIKEY" 8 | 9 | $spaceName = "default" 10 | $feedName = "nuget.org" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | 15 | try 16 | { 17 | # Get space id 18 | $space = $repository.Spaces.FindByName($spaceName) 19 | Write-Host "Using Space named $($space.Name) with id $($space.Id)" 20 | 21 | # Create space specific repository 22 | $repositoryForSpace = [Octopus.Client.OctopusRepositoryExtensions]::ForSpace($repository, $space) 23 | 24 | # Get Existing feed 25 | $feed = $repositoryForSpace.Feeds.FindByName($feedName) 26 | 27 | $repositoryForSpace.Feeds.Delete($feed) | Out-Null 28 | } 29 | catch 30 | { 31 | Write-Host $_.Exception.Message 32 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Feeds/DownloadPackage.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "path\to\Octopus.Client.dll" 3 | 4 | # Octopus variables 5 | $octopusURL = "https://your.octopus.app" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $spaceName = "Default" 8 | $packageName = "packageName" 9 | $packageVersion = "1.0.0.0" 10 | $outputFolder = "C:\Temp\" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get package 23 | $package = $repositoryForSpace = $repositoryForSpace.BuiltInPackageRepository.GetPackage($packageName, $packageVersion) 24 | 25 | # Download Package 26 | $filePath = [System.IO.Path]::Combine($outputFolder, "$($package.PackageId).$($package.Version)$($package.FileExtension)") 27 | Invoke-RestMethod -Method Get -Uri "$octopusURL/$($package.Links.Raw)" -Headers $header -OutFile $filePath 28 | Write-Host "Downloaded file to $filePath" 29 | } 30 | catch 31 | { 32 | Write-Host $_.Exception.Message 33 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Feeds/GetAllFeeds.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path "C:\Octo\Octopus.Client.dll" 4 | 5 | # Octopus variables 6 | $octopusURL = "https://youroctourl" 7 | $octopusAPIKey = "API-YOURAPIKEY" 8 | $spaceName = "default" 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | 13 | try 14 | { 15 | # Get space id 16 | $space = $repository.Spaces.FindByName($spaceName) 17 | Write-Host "Using Space named $($space.Name) with id $($space.Id)" 18 | 19 | # Create space specific repository 20 | $repositoryForSpace = [Octopus.Client.OctopusRepositoryExtensions]::ForSpace($repository, $space) 21 | 22 | # Get all feeds 23 | $feeds = $repositoryForSpace.Feeds.FindAll() 24 | 25 | # Enumerate each feed 26 | foreach($feed in $feeds) 27 | { 28 | $feed 29 | } 30 | } 31 | catch 32 | { 33 | Write-Host $_.Exception.Message 34 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Feeds/PushPackage.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "path\to\Octopus.Client.dll" 3 | 4 | # Octopus variables 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $spaceName = "default" 8 | $packageFile = "path\to\package" 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | $client = New-Object Octopus.Client.OctopusClient $endpoint 13 | $fileStream = $null 14 | 15 | try 16 | { 17 | # Get space 18 | $space = $repository.Spaces.FindByName($spaceName) 19 | $repositoryForSpace = $client.ForSpace($space) 20 | 21 | # Create new package resource 22 | $package = New-Object Octopus.Client.Model.PackageResource 23 | 24 | # Create filestream object 25 | $fileStream = New-Object System.IO.FileStream($packageFile, [System.IO.FileMode]::Open) 26 | 27 | # Push package 28 | $repositoryForSpace.BuiltInPackageRepository.PushPackage($packageFile, $fileStream) 29 | } 30 | catch 31 | { 32 | Write-Host $_.Exception.Message 33 | } 34 | finally 35 | { 36 | if ($null -ne $fileStream) 37 | { 38 | $fileStream.Close() 39 | } 40 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Lifecycles/CreateLifecycle.ps1: -------------------------------------------------------------------------------- 1 | # Load assembly 2 | Add-Type -Path 'path:\to\Octopus.Client.dll' 3 | $octopusURL = "https://YourURL" 4 | $octopusAPIKey = "API-YourAPIKey" 5 | $spaceName = "Default" 6 | $lifecycleName = "MyLifecycle" 7 | 8 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint($octopusURL, $octopusAPIKey) 9 | $repository = New-Object Octopus.Client.OctopusRepository($endpoint) 10 | $client = New-Object Octopus.Client.OctopusClient($endpoint) 11 | 12 | # Get space 13 | $space = $repository.Spaces.FindByName($spaceName) 14 | $repositoryForSpace = $client.ForSpace($space) 15 | 16 | # Check to see if lifecycle already exists 17 | if ($null -eq $repositoryForSpace.Lifecycles.FindByName($lifecycleName)) 18 | { 19 | # Create new lifecyle 20 | $lifecycle = New-Object Octopus.Client.Model.LifecycleResource 21 | $lifecycle.Name = $lifecycleName 22 | $repositoryForSpace.Lifecycles.Create($lifecycle) 23 | } 24 | else 25 | { 26 | Write-Host "$lifecycleName already exists." 27 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Machines/README.md: -------------------------------------------------------------------------------- 1 | # Machines 2 | 3 | You can find scripts related to machines under the [Targets](../Targets) folder. 4 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/ProjectGroups/CreateProjectGroup.ps1: -------------------------------------------------------------------------------- 1 | # Load assembly 2 | Add-Type -Path 'path:\to\Octopus.Client.dll' 3 | $octopusURL = "https://YourURL" 4 | $octopusAPIKey = "API-YourAPIKey" 5 | $spaceName = "Default" 6 | $projectGroupName = "MyProjectGroup" 7 | $projectGroupDescription = "MyDescription" 8 | 9 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint($octopusURL, $octopusAPIKey) 10 | $repository = New-Object Octopus.Client.OctopusRepository($endpoint) 11 | $client = New-Object Octopus.Client.OctopusClient($endpoint) 12 | 13 | # Get space 14 | $space = $repository.Spaces.FindByName($spaceName) 15 | $repositoryForSpace = $client.ForSpace($space) 16 | 17 | # Create project group object 18 | $projectGroup = New-Object Octopus.Client.Model.ProjectGroupResource 19 | $projectGroup.Description = $projectGroupDescription 20 | $projectGroup.Name = $projectGroupName 21 | $projectGroup.EnvironmentIds = $null 22 | $projectGroup.RetentionPolicyId = $null 23 | 24 | $repositoryForSpace.ProjectGroups.Create($projectGroup) -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Projects/CreateAutoDeployTriggersForAllProjects.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-MYAPIKEY' # Get this from your profile 6 | $octopusURI = 'http://MY-OCTOPUS' # Your server address 7 | 8 | $triggerEnvironment = "Dev" # Set this to whatever environment should auto deploy 9 | $triggerRole = "Web-server" # Set this to the deployment target role that should auto deploy 10 | 11 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 12 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 13 | 14 | $environment = $repository.Environments.FindByName($triggerEnvironment) 15 | 16 | $triggerFilter = New-Object Octopus.Client.Model.Triggers.MachineFilterResource 17 | $triggerFilter.EnvironmentIds.Add($environment.Id) 18 | $triggerFilter.Roles.Add($triggerRole) 19 | $triggerFilter.EventGroups.Add("MachineAvailableForDeployment") 20 | 21 | $triggerAction = New-Object Octopus.Client.Model.Triggers.AutoDeployActionResource 22 | $triggerAction.ShouldRedeployWhenMachineHasBeenDeployedTo = $false 23 | 24 | $projects = $repository.Projects.GetAll() 25 | 26 | foreach ($project in $projects) { 27 | $repository.ProjectTriggers.CreateOrModify($project, "Automatically deploy to $triggerRole", $triggerFilter, $triggerAction) 28 | } 29 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Projects/CreateProject.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $projectName = "MyProject" 11 | $projectGroupName = "Default project group" 12 | $lifecycleName = "Default lifecycle" 13 | 14 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 15 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 16 | $client = New-Object Octopus.Client.OctopusClient $endpoint 17 | 18 | try 19 | { 20 | # Get space 21 | $space = $repository.Spaces.FindByName($spaceName) 22 | $repositoryForSpace = $client.ForSpace($space) 23 | 24 | # Get project group 25 | $projectGroup = $repositoryForSpace.ProjectGroups.FindByName($projectGroupName) 26 | 27 | # Get lifecycle 28 | $lifecycle = $repositoryForSpace.Lifecycles.FindByName($lifecycleName) 29 | 30 | # Create new project 31 | $project = $repositoryForSpace.Projects.CreateOrModify($projectName, $projectGroup, $lifecycle) 32 | $project.Save() 33 | } 34 | catch 35 | { 36 | Write-Host $_.Exception.Message 37 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Projects/DeleteProjectByName.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $projectName = "MyProject" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get project 23 | $project = $repositoryForSpace.Projects.FindByName($projectName) 24 | 25 | # Delete project 26 | $repositoryForSpace.Projects.Delete($project) 27 | } 28 | catch 29 | { 30 | Write-Host $_.Exception.Message 31 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Projects/DeleteProjectsWithoutDeploymentProcess.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctopusurl" 8 | $octopusAPIKey = "API-KEY" 9 | $spaceName = "default" 10 | 11 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 12 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 13 | $client = New-Object Octopus.Client.OctopusClient $endpoint 14 | 15 | try 16 | { 17 | # Get space 18 | $space = $repository.Spaces.FindByName($spaceName) 19 | $repositoryForSpace = $client.ForSpace($space) 20 | 21 | # Get project 22 | $projects = $repositoryForSpace.Projects.GetAll() 23 | 24 | # Loop through projects 25 | foreach ($project in $projects) 26 | { 27 | # Get deployment process 28 | $deploymentProcess = $repositoryForSpace.DeploymentProcesses.Get($project.DeploymentProcessId) 29 | 30 | # Check for emtpy process 31 | if (($null -eq $deploymentProcess.Steps) -or ($deploymentProcess.Steps.Count -eq 0)) 32 | { 33 | # Delete project 34 | $repositoryForSpace.Projects.Delete($project) 35 | } 36 | } 37 | } 38 | catch 39 | { 40 | Write-Host $_.Exception.Message 41 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Projects/DisableAllProjectTriggers.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "c:\octopus.client\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $projectName = "MyProject" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get project 23 | $project = $repositoryForSpace.Projects.FindByName($projectName) 24 | 25 | # Get project triggers 26 | $projectTriggers = $repositoryForSpace.Projects.GetAllTriggers($project) 27 | 28 | # Loop through triggers 29 | foreach ($projectTrigger in $projectTriggers) 30 | { 31 | # Disable trigger 32 | $projectTrigger.IsDisabled = $true 33 | $repositoryForSpace.ProjectTriggers.Modify($projectTrigger) | Out-Null 34 | } 35 | } 36 | catch 37 | { 38 | Write-Host $_.Exception.Message 39 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Projects/IgnoreUnavailableMachinesAllProjects.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-MYAPIKEY' # Get this from your profile 6 | $octopusURI = 'http://MY-OCTOPUS' # Your server address 7 | 8 | $roles = "web-server", "app-server" # The roles that are transient 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | 13 | $projects = $repository.Projects.GetAll() 14 | $projects | % { 15 | $project = $_ 16 | $project.ProjectConnectivityPolicy.SkipMachineBehavior = [Octopus.Client.Model.SkipMachineBehavior]::SkipUnavailableMachines 17 | $roles | % { $project.ProjectConnectivityPolicy.TargetRoles.Add($_) } 18 | $repository.Projects.Modify($project) 19 | } 20 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Releases/DeleteReleasesForProject.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $projectName = "MyProject" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get project 23 | $project = $repositoryForSpace.Projects.FindByName($projectName) 24 | 25 | # Get releases 26 | $releases = $repositoryForSpace.Releases.FindMany({param($r) $r.ProjectId -eq $project.Id}) 27 | 28 | # Loop through results 29 | foreach ($release in $releases) 30 | { 31 | # Delete release 32 | $repositoryForSpace.Releases.Delete($release) 33 | } 34 | } 35 | catch 36 | { 37 | Write-Host $_.Exception.Message 38 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Releases/UpdateReleaseVariableSnapshot.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | # Octopus variables 6 | $octopusURL = "https://youroctourl" 7 | $octopusAPIKey = "API-YOURAPIKEY" 8 | $spaceName = "default" 9 | $projectName = "MyProject" 10 | $channelName = "default" 11 | $releaseVersion = "1.0.0.0" 12 | 13 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 14 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 15 | $client = New-Object Octopus.Client.OctopusClient $endpoint 16 | 17 | try 18 | { 19 | # Get space 20 | $space = $repository.Spaces.FindByName($spaceName) 21 | $repositoryForSpace = $client.ForSpace($space) 22 | 23 | # Get project 24 | $project = $repositoryForSpace.Projects.FindByName($projectName) 25 | 26 | # Get channel 27 | $channel = $repositoryForSpace.Channels.FindOne({param($c) $c.Name -eq $channelName -and $c.ProjectId -eq $project.Id}) 28 | 29 | # Get the release 30 | $release = $repositoryForSpace.Releases.FindOne({param($r) $r.ChannelId -eq $channel.Id -and $r.ProjectId -eq $project.Id -and $r.Version -eq $releaseVersion}) 31 | 32 | # Get new variable snapshot 33 | $repositoryForSpace.Releases.SnapshotVariables($release) 34 | } 35 | catch 36 | { 37 | Write-Host $_.Exception.Message 38 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Spaces/DeleteSpace.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'path\to\Octopus.Client.dll' 4 | 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | 8 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint($octopusURL, $octopusAPIKey) 9 | $repository = New-Object Octopus.Client.OctopusRepository($endpoint) 10 | 11 | $spaceName = "New Space" 12 | 13 | $space = $repository.Spaces.FindByName($spaceName) 14 | 15 | if ($null -eq $space) { 16 | Write-Host "The space $spaceName does not exist." 17 | exit 18 | } 19 | 20 | try { 21 | $space.TaskQueueStopped = $true 22 | 23 | $repository.Spaces.Modify($space) | Out-Null 24 | $repository.Spaces.Delete($space) | Out-Null 25 | } catch { 26 | Write-Host $_.Exception.Message 27 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Tagsets/AddTagToTagset.ps1: -------------------------------------------------------------------------------- 1 | Add-Type -Path "C:\Tools\Octopus.Client.dll" 2 | 3 | $apikey = '' #Your Octopus API Key 4 | $octopusURI = '' #Your Octopus instance URL 5 | 6 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI, $apiKey 7 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 8 | 9 | $tagset = $repository.TagSets.FindByName("MyTagset") 10 | 11 | $newtag = New-Object Octopus.Client.Model.TagResource 12 | 13 | $newtag.Name = "MyNewTag" 14 | $newtag.Color = "#232323" 15 | #Modify any other properties of $newTag here 16 | 17 | $tagset.Tags.Add($newtag) #You might wanna double check that a tag with that name doesn't exist here. 18 | 19 | $repository.TagSets.Modify($tagset) 20 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Tagsets/CreateTagSet.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "path\to\Octopus.Client.dll" 3 | 4 | # Define working variables 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $spaceName = "Default" 8 | $tagsetName = "Upgrade Ring" 9 | $tagsetDescription = "Describes which upgrade ring the tenant belongs to" 10 | 11 | # Optional Tags to add in the format "Tag name", "Tag Color" 12 | $optionalTags = @{} 13 | $optionalTags.Add("Early Adopter", "#ECAD3F") 14 | $optionalTags.Add("Stable", "#36A766") 15 | 16 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 17 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 18 | $client = New-Object Octopus.Client.OctopusClient $endpoint 19 | 20 | try 21 | { 22 | # Get space 23 | $space = $repository.Spaces.FindByName($spaceName) 24 | $repositoryForSpace = $client.ForSpace($space) 25 | 26 | # Create or modify tagset 27 | $tagsetEditor = $repositoryForSpace.TagSets.CreateOrModify($tagsetName, $tagsetDescription) 28 | 29 | # Add optional tags 30 | if($optionalTags.Count -gt 0) 31 | { 32 | foreach ($tagName in $optionalTags.Keys) { 33 | $tagsetEditor.AddOrUpdateTag($tagName, "", $optionalTags.Item($tagName)) 34 | } 35 | 36 | } 37 | $tagsetEditor.Save() 38 | } 39 | catch 40 | { 41 | Write-Host $_.Exception.Message 42 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/AddRoleToAllMachines.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-XXXXXXXXXXXXXXXXXXXXXX' # Get this from your profile 6 | $octopusURI = 'https://octopus.url' # Your server address 7 | 8 | $role = "A new role" # The role to add to each machine 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | 13 | $machines = $repository.Machines.FindAll(); 14 | 15 | foreach ($machine in $machines) { 16 | $machine.Roles.Add($role) 17 | $repository.Machines.Modify($machine) 18 | } 19 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/AddRoleToTarget.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "c:\octopus.client\Octopus.Client.dll" 3 | 4 | # Octopus variables 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $spaceName = "default" 8 | $machineName = "MyMachine" 9 | $targetRole = "MyRole" 10 | 11 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 12 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 13 | $client = New-Object Octopus.Client.OctopusClient $endpoint 14 | 15 | try 16 | { 17 | # Get space 18 | $space = $repository.Spaces.FindByName($spaceName) 19 | $repositoryForSpace = $client.ForSpace($space) 20 | 21 | # Get machine 22 | $machine = $repositoryForSpace.Machines.FindByName($machineName) 23 | 24 | # Add target role 25 | $machine.roles.Add($targetRole) 26 | $repositoryForSpace.Machines.Modify($machine) 27 | } 28 | catch 29 | { 30 | Write-Host $_.Exception.Message 31 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/ChangeTargetMachinePolicy.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "c:\octopus.client\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $machineName = "MyMachine" 11 | $machinePolicyName = "MyPolicy" 12 | 13 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 14 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 15 | $client = New-Object Octopus.Client.OctopusClient $endpoint 16 | 17 | try 18 | { 19 | # Get space 20 | $space = $repository.Spaces.FindByName($spaceName) 21 | $repositoryForSpace = $client.ForSpace($space) 22 | 23 | # Get machine list 24 | $machine = $repositoryForSpace.Machines.FindByName($machineName) 25 | 26 | # Get machine policy 27 | $machinePolicy = $repositoryForSpace.MachinePolicies.FindByName($machinePolicyName) 28 | 29 | # Change machine policy for machine 30 | $machine.MachinePolicyId = $machinePolicy.Id 31 | $repositoryForSpace.Machines.Modify($machine) 32 | } 33 | catch 34 | { 35 | Write-Host $_.Exception.Message 36 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/CountMachineAndEnvironments.ps1: -------------------------------------------------------------------------------- 1 | $apikey = 'XXXXXX' # Get this from your profile 2 | $OctopusUrl = 'https://OctopusURL/' # Your Octopus Server address 3 | $spaceName = "Default" # Name of the Space 4 | ​ 5 | # You can get this dll from NuGet 6 | # https://www.nuget.org/packages/Octopus.Client/ 7 | ​ 8 | Add-Type -Path 'Octopus.Client.dll' 9 | ​ 10 | # Set up endpoint and Spaces repository 11 | $endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusUrl, $APIKey 12 | $client = new-object Octopus.Client.OctopusClient $endpoint 13 | ​ 14 | # Find Space 15 | $space = $client.ForSystem().Spaces.FindByName($spaceName) 16 | $spaceRepository = $client.ForSpace($space) 17 | ​ 18 | # Get Counts 19 | $environments = $spaceRepository.Environments.FindAll() 20 | $envCount = $environments.Count 21 | $machines = $spaceRepository.Machines.FindAll() 22 | $machineCount = $machines.Count 23 | $projects = $spaceRepository.Projects.FindAll() 24 | $projCount = $projects.Count 25 | ​ 26 | Write-Output "Space '$spaceName' has Environment count: $envCount" 27 | Write-Output "Space '$spaceName' has Machine count: $machineCount" 28 | Write-Output "Space '$spaceName' has Project count: $projCount" -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/DeleteMachinesByRole.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://your.octopus.app" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $role = "MyRole" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get machine list 23 | $machines = $repositoryForSpace.Machines.GetAll() | Where-Object {$role -in $_.Roles} 24 | 25 | # Loop through list 26 | foreach ($machine in $machines) 27 | { 28 | # Delete machine 29 | $repositoryForSpace.Machines.Delete($machine) 30 | } 31 | } 32 | catch 33 | { 34 | Write-Host $_.Exception.Message 35 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/DeleteTargetByName.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl/api" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $machineName = "MachineName" 11 | 12 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 13 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 14 | $client = New-Object Octopus.Client.OctopusClient $endpoint 15 | 16 | try 17 | { 18 | # Get space 19 | $space = $repository.Spaces.FindByName($spaceName) 20 | $repositoryForSpace = $client.ForSpace($space) 21 | 22 | # Get machine 23 | $machine = $repositoryForSpace.Machines.FindByName($machineName) 24 | 25 | # Delete machine 26 | $repositoryForSpace.Machines.Delete($machine) 27 | } 28 | catch 29 | { 30 | Write-Host $_.Exception.Message 31 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/EnableOrDisableAMachine.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "path\to\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $machineName = "MyMachine" 11 | $machineEnabled = $true 12 | 13 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 14 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 15 | $client = New-Object Octopus.Client.OctopusClient $endpoint 16 | 17 | try 18 | { 19 | # Get space 20 | $space = $repository.Spaces.FindByName($spaceName) 21 | $repositoryForSpace = $client.ForSpace($space) 22 | 23 | # Get machine 24 | $machine = $repositoryForSpace.Machines.FindByName($machineName) 25 | 26 | # Enable/disable machine 27 | $machine.IsDisabled = !$machineEnabled 28 | 29 | # Update machine 30 | $repositoryForSpace.Machines.Modify($machine) 31 | } 32 | catch 33 | { 34 | Write-Host $_.Exception.Message 35 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/ListMachinesInDeployment.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-xxx' # Get this from your profile 6 | $octopusURI = 'http://octopus' # Your server address 7 | 8 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 9 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 10 | 11 | $machineIds = $OctopusParameters['Octopus.Deployment.Machines'].Split(',') 12 | 13 | foreach ($machineId in $machineIds) { 14 | $machine = $repository.Machines.Get($machineId) 15 | Write-Host $machine.Name 16 | } 17 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Targets/UpgradeTargets.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "path\to\Octopus.Client.dll" 3 | 4 | # Octopus variables 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $spaceName = "default" 8 | $machineNames = @("MyMachine") 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | $client = New-Object Octopus.Client.OctopusClient $endpoint 13 | 14 | try 15 | { 16 | # Get space 17 | $space = $repository.Spaces.FindByName($spaceName) 18 | $repositoryForSpace = $client.ForSpace($space) 19 | 20 | # Get machines 21 | $machines = @() 22 | foreach ($machineName in $machineNames) 23 | { 24 | # Get machine 25 | $machine = $repositoryForSpace.Machines.FindByName($machineName) 26 | $machines += $machine.Id 27 | } 28 | 29 | # Create new task resource 30 | $task = New-Object Octopus.Client.Model.TaskResource 31 | $task.Name = "Upgrade" 32 | $task.Description = "Upgrade machines" 33 | $task.Arguments.Add("MachineIds", $machines) 34 | 35 | # Execute 36 | $repositoryForSpace.Tasks.Create($task) 37 | } 38 | catch 39 | { 40 | Write-Host $_.Exception.Message 41 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Users/APIKey_Create.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "C:\octo\Octopus.Client.dll" 3 | 4 | # Define working variables 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | 8 | # Purpose of the API Key. This field is mandatory. 9 | $APIKeyPurpose = "" 10 | 11 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 12 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 13 | 14 | try 15 | { 16 | # Get Current user 17 | $User = $repository.Users.GetCurrent() 18 | 19 | # Create API Key for user 20 | $ApiKeyResponse = $repository.Users.CreateApiKey($User, $APIKeyPurpose) 21 | 22 | # Return the API Key 23 | Write-Output "API Key created: $($ApiKeyResponse.ApiKey)" 24 | } 25 | catch 26 | { 27 | Write-Host $_.Exception.Message 28 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Users/FindInactiveUsers.ps1: -------------------------------------------------------------------------------- 1 | # Find any users that have not been active on Octopus in the last 90 days 2 | $octopusURL = "https://your-octopus-instance/" 3 | $octopusAPIKey = "API-xxxx" 4 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 5 | 6 | $endDate = Get-Date -format "yyyy-MM-dd" 7 | $startDate = (Get-Date).AddDays(-90).ToString("yyyy-MM-dd") 8 | 9 | # Get users 10 | $users = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/users" -Headers $header 11 | 12 | Write-Host "Users not active in last 90 days:" 13 | 14 | foreach ($user in $users.Items) { 15 | # Get events 16 | $audit = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/events?users=$($user.Id)&from=$($startDate)T00%3A00%3A00%2B00%3A00&to=$($endDate)T23%3A59%3A59%2B00%3A00&spaces=all&includeSystem=false&excludeDifference=true" -Headers $header 17 | 18 | if ($audit.TotalResults -eq 0){ 19 | Write-Host " $($user.Username)" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Variables/AddLibraryVariableSetToAllProjects.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-ABC123' # Get this from your profile 6 | $octopusURI = 'http://octopus-uri' # Your server address 7 | 8 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 9 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 10 | 11 | 12 | $libraryVariableSet = New-Object Octopus.Client.Model.LibraryVariableSetResource 13 | $libraryVariableSet.Name = "Ignore config transform errors" 14 | $libraryVariableSet = $repository.LibraryVariableSets.Create($libraryVariableSet) 15 | 16 | $ignoreConfigTransformVariable = new-object Octopus.Client.Model.VariableResource 17 | $ignoreConfigTransformVariable.Name = "Octopus.Action.Package.IgnoreConfigTransformationErrors" 18 | $ignoreConfigTransformVariable.Value = "true" 19 | 20 | $variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId) 21 | $variables.Variables.Add($ignoreConfigTransformVariable) 22 | $repository.VariableSets.Modify($variables) 23 | 24 | $projects = $repository.Projects.FindAll() 25 | foreach ($project in $projects) { 26 | $project.IncludedLibraryVariableSetIds.Add($libraryVariableSet.Id) 27 | $repository.Projects.Modify($project) 28 | } 29 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Variables/AddLibraryVariableSetToSelectedProjects.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | # Load octopus.client assembly 4 | Add-Type -Path "c:\octopus.client\Octopus.Client.dll" 5 | 6 | # Octopus variables 7 | $octopusURL = "https://youroctourl" 8 | $octopusAPIKey = "API-YOURAPIKEY" 9 | $spaceName = "default" 10 | $projectName = "MyProject" 11 | $libararySetName = "MyLibrarySet" 12 | 13 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 14 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 15 | $client = New-Object Octopus.Client.OctopusClient $endpoint 16 | 17 | try 18 | { 19 | # Get space 20 | $space = $repository.Spaces.FindByName($spaceName) 21 | $repositoryForSpace = $client.ForSpace($space) 22 | 23 | # Get project 24 | $project = $repositoryForSpace.Projects.FindByName($projectName) 25 | 26 | # Get library set 27 | $librarySet = $repositoryForSpace.LibraryVariableSets.FindByName($libararySetName) 28 | 29 | # Add set to project 30 | $project.IncludedLibraryVariableSetIds += $librarySet.Id 31 | 32 | # Update project 33 | $repositoryForSpace.Projects.Modify($project) 34 | } 35 | catch 36 | { 37 | Write-Host $_.Exception.Message 38 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Variables/AddVariableToLibraryVariableSet.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | Add-Type -Path 'Octopus.Client.dll' 4 | 5 | $apikey = 'API-MCPLE1AQM2VKTRFDLIBMORQHBXA' # Get this from your profile 6 | $octopusURI = 'http://localhost' # Your server address 7 | 8 | $libraryVariableSetId = "LibraryVariableSets-1" # Get this from /api/libraryvariablesets 9 | $variableName = "Variable name" # Name of the new variable 10 | $variableValue = "Variable value" # Value of the new variable 11 | 12 | $endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 13 | $repository = new-object Octopus.Client.OctopusRepository $endpoint 14 | 15 | $libraryVariableSet = $repository.LibraryVariableSets.Get($libraryVariableSetId); 16 | $variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId); 17 | 18 | $myNewVariable = new-object Octopus.Client.Model.VariableResource 19 | $myNewVariable.Name = $variableName 20 | $myNewVariable.Value = $variableValue 21 | 22 | $variables.Variables.Add($myNewVariable) 23 | $repository.VariableSets.Modify($variables) 24 | -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Variables/FindProjectsThatUseALibraryVariableSet.ps1: -------------------------------------------------------------------------------- 1 | # Load octopus.client assembly 2 | Add-Type -Path "path\to\Octopus.Client.dll" 3 | 4 | # Octopus variables 5 | $octopusURL = "https://youroctourl" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $spaceName = "default" 8 | $librarySetName = "MyLibrarySet" 9 | 10 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $octopusAPIKey 11 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 12 | $client = New-Object Octopus.Client.OctopusClient $endpoint 13 | 14 | try 15 | { 16 | # Get space 17 | $space = $repository.Spaces.FindByName($spaceName) 18 | $repositoryForSpace = $client.ForSpace($space) 19 | 20 | # Get Library set 21 | $librarySet = $repositoryForSpace.LibraryVariableSets.FindByName($librarySetName) 22 | 23 | # Get Projects 24 | $projects = $repositoryForSpace.Projects.GetAll() 25 | 26 | # Show all projects using set 27 | Write-Host "The following projects are using $librarySetName" 28 | foreach ($project in $projects) 29 | { 30 | if ($project.IncludedLibraryVariableSetIds -contains $librarySet.Id) 31 | { 32 | Write-Host "$($project.Name)" 33 | } 34 | } 35 | } 36 | catch 37 | { 38 | Write-Host $_.Exception.Message 39 | } -------------------------------------------------------------------------------- /Octopus.Client/PowerShell/Variables/find-variables-scoped-to-steps.ps1: -------------------------------------------------------------------------------- 1 | # You can get this dll from NuGet 2 | # https://www.nuget.org/packages/Octopus.Client/ 3 | 4 | Add-Type -Path 'C:\MyScripts\Octopus.Client\Octopus.Client.dll' 5 | 6 | $apikey = 'API-XXXXXXXXXXXXXXXXXXXXXXXXXX' # Get this from your profile 7 | $octopusURI = 'https://octopus.url' # Your Octopus Server address 8 | 9 | $projectName = "TestProp" # Enter project you want to search 10 | 11 | $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI, $apiKey 12 | $repository = New-Object Octopus.Client.OctopusRepository $endpoint 13 | 14 | $project = $repository.Projects.FindByName($projectName) 15 | $projectVariables = $repository.VariableSets.Get($project.VariableSetId) 16 | 17 | foreach ($variables in $projectVariables.Variables) # For each Variable in referenced project - Return Variable Name & Value 18 | { 19 | Write-Host "###########################" 20 | Write-Host "Variable Name = ", $variables.Name 21 | Write-Host "Variable Value = ", $variables.Value 22 | 23 | $scopeId = $variables.Scope.Values # Get Scope ID for each Variable 24 | 25 | foreach ($x in $projectVariables.ScopeValues.Actions) # Compare Scope ID to Scope value 26 | { 27 | if ($x.Id -eq $scopeId) # Return Scope Name if ID matches 28 | { 29 | Write-Host "Scoped to Step = ", $x.Name 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Octopus Deploy API Examples 2 | 3 | [Octopus Deploy](https://octopus.com/) is a user-friendly automated deployment tool for developers. This GitHub repository exists to provide code snippet samples for various operations in the Octopus REST API. 4 | 5 | You'll find examples written in a number of languages including: 6 | 7 | - Go 8 | - Java 9 | - .NET (C#) 10 | - PowerShell 11 | - Python 12 | 13 | [Find out more about the Octopus REST API in our documentation](https://octopus.com/docs/octopus-rest-api). 14 | -------------------------------------------------------------------------------- /REST/Golang/Project-Groups/ListProjectGroups/listProjectGroups.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "log" 7 | "net/http" 8 | "os" 9 | ) 10 | 11 | func main() { 12 | url := os.Args[1] 13 | apiKey := os.Args[2] 14 | 15 | response, err := http.NewRequest("GET", url+"/api/projectgroups", nil) 16 | response.Header.Set("X-Octopus-ApiKey", apiKey) 17 | 18 | if err != nil { 19 | log.Println(err) 20 | } 21 | 22 | client := &http.Client{} 23 | resp, _ := client.Do(response) 24 | 25 | output, _ := ioutil.ReadAll(resp.Body) 26 | fmt.Println(string(output)) 27 | } 28 | -------------------------------------------------------------------------------- /REST/Golang/Projects/ListProjects/listProjects.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "log" 7 | "net/http" 8 | "os" 9 | ) 10 | 11 | func main() { 12 | url := os.Args[1] 13 | apiKey := os.Args[2] 14 | 15 | response, err := http.NewRequest("GET", url+"/api/projects", nil) 16 | response.Header.Set("X-Octopus-ApiKey", apiKey) 17 | 18 | if err != nil { 19 | log.Println(err) 20 | } 21 | 22 | client := &http.Client{} 23 | resp, _ := client.Do(response) 24 | 25 | output, _ := ioutil.ReadAll(resp.Body) 26 | fmt.Println(string(output)) 27 | } 28 | -------------------------------------------------------------------------------- /REST/Golang/go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | require ( 4 | github.com/OctopusDeploy/go-octopusdeploy v1.7.31 5 | github.com/google/uuid v1.3.0 6 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 7 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 8 | ) 9 | 10 | go 1.13 11 | -------------------------------------------------------------------------------- /REST/Golang/vendor/HashAPIKey/hashpass.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | "golang.org/x/crypto/ssh/terminal" 8 | ) 9 | 10 | func main() { 11 | hashpass() 12 | } 13 | 14 | func hashpass() { 15 | fmt.Println("Enter Password Securely: ") 16 | apiKey, err := terminal.ReadPassword(0) 17 | 18 | if err != nil { 19 | log.Println(err) 20 | } 21 | 22 | APIKey := string(apiKey) 23 | } 24 | -------------------------------------------------------------------------------- /REST/PowerShell/Accounts/RemoveAssociatedTenantFromAccount.ps1: -------------------------------------------------------------------------------- 1 | $OctopusServerUrl = "https://YOUR_OCTOPUS_URL" #PUT YOUR SERVER LOCATION HERE. (e.g. http://localhost) 2 | $ApiKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" #PUT YOUR API KEY HERE 3 | $SpaceId = "Spaces-XX" # (e.g. Spaces-1) 4 | $TenantId = "Tenants-XX" #TenantID to remove (e.g. Tenants-12) 5 | $AccountId = "Accounts-XX" #AccountID to modify (e.g. Accounts-213) 6 | 7 | $Body = Invoke-RestMethod -Method Get -Uri "$OctopusServerUrl/api/$($SpaceId)/accounts/$($AccountId)" -Headers @{"X-Octopus-ApiKey" = "$ApiKey" } 8 | 9 | $NewTenantList = @() 10 | $Tenants = $Body.TenantIds 11 | 12 | Foreach ($Tenant in $Tenants) { 13 | Write-Host "$($Tenant)" 14 | if ($Tenant -eq $TenantId) { 15 | Write-Host "$($TenantId) removed from $($AccountId)" 16 | } 17 | 18 | if ($Tenant -ne $TenantId) { 19 | $NewTenantList += $Tenant 20 | } 21 | } 22 | 23 | $Body.TenantIds = $NewTenantList 24 | 25 | Invoke-RestMethod -Method PUT -Uri "$OctopusServerUrl/api/$($SpaceId)/accounts/$($AccountId)" -Headers @{"X-Octopus-ApiKey" = "$ApiKey" } -body ($Body | ConvertTo-Json) -------------------------------------------------------------------------------- /REST/PowerShell/Administration/CheckForMonoUsage.ps1: -------------------------------------------------------------------------------- 1 | $octopusBaseURL = "https://your.octopus.app/api" 2 | $octopusAPIKey = "API-yourapikey" 3 | $headers = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 4 | 5 | $spaceNames = @("Default") 6 | 7 | # Get space id 8 | $spaces = Invoke-RestMethod -Method Get -Uri "$octopusBaseURL/spaces/all" -Headers $headers 9 | 10 | foreach($spaceName in $spaceNames) { 11 | $space = $spaces | Where-Object { $_.Name -eq $spaceName } 12 | Write-Host "Using Space named $($space.Name) with id $($space.Id)" 13 | 14 | # Create space specific url 15 | $octopusSpaceUrl = "$octopusBaseURL/$($space.Id)" 16 | 17 | $targets = @() 18 | $workers = @() 19 | $targets = Invoke-RestMethod -Method Get -Uri "$octopusSpaceUrl/machines/all" -Headers $headers 20 | $workers = Invoke-RestMethod -Method Get -Uri "$octopusSpaceUrl/workers/all" -Headers $headers 21 | 22 | ($targets + $workers) 23 | | Where-Object { $_.Endpoint -and $_.Endpoint.CommunicationStyle -and $_.Endpoint.CommunicationStyle -eq "Ssh" -and $_.Endpoint.DotNetCorePlatform -eq $null } 24 | | ForEach-Object { 25 | Write-Host "SSH connection $($_.Name) ($($_.Id)) is still running Mono. Time to convert to .NET Core!" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /REST/PowerShell/Administration/GetMaintenanceModeStatus.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | $OctopusAPIkey = "" #Your Octopus API Key 3 | $OctopusURL = "" #Your Octopus Server root URL 4 | 5 | 6 | ##PROCESS## 7 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 8 | $MaintenanceConfig = ((Invoke-WebRequest $OctopusURL/api/maintenanceconfiguration -Method GET -Headers $header).content | ConvertFrom-Json).IsInMaintenanceMode 9 | Write-host $MaintenanceConfig -------------------------------------------------------------------------------- /REST/PowerShell/Administration/UpdateMaintenanceModeStatus.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | $OctopusAPIkey = "" #Your Octopus API Key 3 | $OctopusURL = "" #Your Octopus Server root URL 4 | $MaintanceModeValue = "true" #True or false to enable/disable mainteancemode 5 | $jsonPayload = @{ 6 | IsInMaintenanceMode=$MaintanceModeValue 7 | } 8 | 9 | ##PROCESS## 10 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 11 | $MaintenanceConfig = Invoke-RestMethod $OctopusURL/api/maintenanceconfiguration -Method PUT -Body ($jsonPayload | ConvertTo-Json -Depth 10) -Headers $header 12 | Write-host $MaintenanceConfig 13 | -------------------------------------------------------------------------------- /REST/PowerShell/Channels/CreateChannel.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $projectId = "Projects-101" 9 | $channelName = "Channel Name" 10 | 11 | # Get space 12 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 13 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 14 | 15 | # Create channel json payload 16 | $jsonPayload = @{ 17 | ProjectId = $projectId; 18 | SpaceId = $space.Id; 19 | Name = $channelName; 20 | Description = ""; 21 | IsDefault = $False; 22 | } 23 | 24 | # Create channel 25 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/channels" -Body ($jsonPayload | ConvertTo-Json -Depth 10) -Headers $header -ContentType "application/json" -------------------------------------------------------------------------------- /REST/PowerShell/DeploymentProcesses/FindAllProjectsByRole.ps1: -------------------------------------------------------------------------------- 1 | $OctopusUrl = "" # Your URL 2 | $ApiKey = "" # Your API Key 3 | $roleName = "FileBackup" 4 | $header = @{ "X-Octopus-ApiKey" = $ApiKey } 5 | 6 | $projectList = Invoke-RestMethod "$octopusUrl/api/$spaceId/projects?skip=0&take=10000" -Headers $header 7 | $projectsWithRoles = @() 8 | 9 | foreach ($project in $projectList.Items) 10 | { 11 | $deploymentProcessUrl = $OctopusUrl + $project.Links.DeploymentProcess 12 | $projectDeploymentProcess = Invoke-RestMethod $deploymentProcessUrl -Headers $header 13 | 14 | foreach ($step in $projectDeploymentProcess.Steps) 15 | { 16 | if ($step.Properties.'Octopus.Action.TargetRoles' -contains $roleName) 17 | { 18 | $projectsWithRoles += $project.Name 19 | break 20 | } 21 | } 22 | } 23 | 24 | Write-Host "The following projects have $roleName" 25 | foreach ($projectName in $projectsWithRoles) 26 | { 27 | Write-Host $projectName 28 | } -------------------------------------------------------------------------------- /REST/PowerShell/DeploymentProcesses/RemoveARCSettingsFromProject.ps1: -------------------------------------------------------------------------------- 1 | #Script written to fix http://help.octopusdeploy.com/discussions/problems/48848 2 | 3 | ##CONFIG## 4 | $OctopusAPIkey = "" #Octopus API Key 5 | $OctopusURL = "" #Octopus root url 6 | $ProjectName = "" #Name of the project 7 | 8 | ##PROCESS## 9 | 10 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 11 | 12 | $allprojects = (Invoke-WebRequest $OctopusURL/api/projects/all -Headers $header).content | ConvertFrom-Json 13 | 14 | $project = $allprojects | ?{$_.name -eq $ProjectName} 15 | 16 | If($project -ne $null){ 17 | $project.AutoCreateRelease = $false 18 | $project.ReleaseCreationStrategy.ReleaseCreationPackageStepId = "" 19 | $project.ReleaseCreationStrategy.ChannelId = $null 20 | $project.VersioningStrategy.DonorPackageStepId = $null 21 | $Project.VersioningStrategy.Template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}" 22 | 23 | $projectJson = $project | ConvertTo-Json 24 | 25 | Invoke-WebRequest $OctopusURL/api/projects/$($project.id) -Method Put -Headers $header -Body $projectJson 26 | } 27 | 28 | Else{ 29 | Write-Error "Project [$ProjectName] not found in $OctopusURL" 30 | } -------------------------------------------------------------------------------- /REST/PowerShell/Deployments/CancelDeployment.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | 3 | $OctopusURL = "" #Octopus URL 4 | $OctopusAPIKey = "" #Octopus API Key 5 | 6 | $ProjectName = "" #Name of the project that owns the deployment 7 | $EnvironmentName = "" #Name of the environment where the deployment is taking place 8 | 9 | 10 | ##PROCESS## 11 | 12 | $header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } 13 | 14 | #Get dashboard to get latest deployments 15 | $dashboard = (Invoke-WebRequest "$OctopusURL/api/dashboard" -Method Get -Headers $header).content | ConvertFrom-Json 16 | 17 | #Get the Environment and Project to filter later 18 | $Environment = $dashboard.Environments | ?{$_.name -eq $EnvironmentName} 19 | $Project = $dashboard.Projects | ?{$_.name -eq $ProjectName} 20 | 21 | #Get the deployment 22 | $Deployment = $dashboard.Items | ?{($_.ProjectID -eq $Project.Id) -and ($_.EnvironmentID -eq $Environment.id)} | sort -Descending -Property Created |select -First 1 23 | 24 | 25 | #Cancel the task asociated with the deployment 26 | Invoke-WebRequest ("$OctopusURL" + $Deployment.links.Task + "/cancel") -Method Post -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Deployments/CancelQueuedDeployments.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | 9 | # Get space 10 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 11 | 12 | $canContinue = $true 13 | 14 | while ($canContinue -eq $true) 15 | { 16 | # Get tasks 17 | $tasks = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/tasks?States=Queued&Name=Deploy" -Headers $header 18 | 19 | # Loop through tasks 20 | foreach ($task in $tasks.Items) 21 | { 22 | # Cancel task 23 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/tasks/$($task.Id)/cancel" -Headers $header 24 | } 25 | 26 | $canContinue = $tasks.NumberOfPages -gt 1 27 | } -------------------------------------------------------------------------------- /REST/PowerShell/Deployments/FailDeploymentIfHasWarningsOrErrorsIsTrue.PS1: -------------------------------------------------------------------------------- 1 | # Use the script below in a "Run a Script" step to fail a deployment where "HasWarningsOrErrors" is true in the JSON for the $serverTaskID. 2 | 3 | $ErrorActionPreference = "Stop"; 4 | 5 | # Define working variables 6 | $octopusURL = "https://YOUR_OCTOPUS_URL" 7 | $octopusAPIKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 8 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 9 | $spaceID = $OctopusParameters["Octopus.Space.Id"] 10 | $serverTaskID = $OctopusParameters["Octopus.Task.Id"] 11 | 12 | $serverTaskJSON = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($spaceID)/tasks/$($serverTaskID)" -Headers $header 13 | If ($serverTaskJSON.HasWarningsOrErrors) { 14 | Write-Error "This deployment contains warnings or errors. Failing deployment..." 15 | } 16 | -------------------------------------------------------------------------------- /REST/PowerShell/Deployments/GetListOfDeploymentsToSpecificEnvironment.ps1: -------------------------------------------------------------------------------- 1 | $octopusApiKey = "YOUR API KEY" 2 | $octopusUrl = "YOUR URL" 3 | $spaceName = "Default" 4 | $environmentName = "Production" 5 | 6 | $header = @{"X-Octopus-ApiKey" = "$octopusApiKey" } 7 | 8 | $spaceList = Invoke-RestMethod -Uri "$octopusUrl/api/spaces?partialName=$([System.Web.HTTPUtility]::UrlEncode($spaceName))&skip=0&take=1" -Headers $header 9 | $space = $spaceList.Items[0] 10 | 11 | $dashboardInformation = Invoke-RestMethod -Uri "$octopusUrl/api/$($space.Id)/dashboard?highestLatestVersionPerProjectAndEnvironment=true" -Headers $header 12 | $environmentToUse = $dashboardInformation.Environments | Where-Object {$_.Name -eq $environmentName} 13 | $deploymentsToEnvironment = @($dashboardInformation.Items | Where-Object {$_.EnvironmentId -eq $environmentToUse.Id}) 14 | 15 | foreach ($deployment in $deploymentsToEnvironment) 16 | { 17 | $project = $dashboardInformation.Projects | Where-Object { $_.Id -eq $deployment.ProjectId } 18 | $tenantName = $null 19 | 20 | if ($null -ne $deployment.TenantId) 21 | { 22 | $tenant = $dashboardInformation.Tenants | Where-Object { $_.Id -eq $deployment.TenantId } 23 | $tenantName = $tenant.Name 24 | } 25 | 26 | Write-Host "$($project.Name) $tenantName $($deployment.ReleaseVersion)" 27 | } -------------------------------------------------------------------------------- /REST/PowerShell/Deployments/deletedeployment.ps1: -------------------------------------------------------------------------------- 1 | $octopusAPIKey = "" 2 | $octopusURL = "" 3 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 4 | 5 | #To get the deployment ID, click on the deployment and you'll reach a URL similar to this: https://octopus.urlapp#/projects/Projects-2/releases/1.0.142/deployments/Deployments-744 6 | #The deployment ID in that case is Deployments-744 7 | $deploymentID = "" 8 | 9 | Invoke-RestMethod "$octopusURL/api/deployments/$deploymentID" -Method Delete -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Events/FindByDate.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "http://octotemp" 5 | $octopusAPIKey = "API-APIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $eventDate = "9/9/2020" 8 | 9 | # Get space 10 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 11 | 12 | # Get events 13 | $events = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/events" -Headers $header).Items | Where-Object {([datetime]$_.Occurred -ge [datetime]$eventDate) -and ([datetime]$_.Occurred -le ([datetime]$eventDate).AddDays(1).AddSeconds(-1))} 14 | 15 | # Display events 16 | foreach ($event in $events) 17 | { 18 | $event 19 | } -------------------------------------------------------------------------------- /REST/PowerShell/Events/GetAuditLogForEntity.ps1: -------------------------------------------------------------------------------- 1 | $EntityId = "" #the id of the object you want to get the events for. Usually can be obtained from the address bar in the browser 2 | $OctopusURL = "" #url of your octopus server 3 | $OctopusAPIkey = "" #API Key to authenticate in Octopus. 4 | 5 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 6 | $json = (Invoke-WebRequest $OctopusURL/api/events?regarding=$EntityId -Headers $header -Method Get -UseBasicParsing).content 7 | ($json | ConvertFrom-Json).items | select-object {$_.Username, $_.Occurred, $_.Message} 8 | -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/ChangeFeed.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $feedName = "nuget.org" 9 | 10 | # Change property 11 | $newFeedName = "nuget.org feed" 12 | 13 | # Get space 14 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 15 | 16 | # Get feed 17 | $feed = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/feeds/all" -Headers $header) | Where-Object {$_.Name -eq $feedName} 18 | 19 | # Change feed name 20 | $feed.Name = $newFeedName 21 | 22 | # Update feed in Octopus 23 | Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/feeds/$($feed.Id)" -Body ($feed | ConvertTo-Json -Depth 10) -Headers $header -Method Put -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/CreateFeed.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $feedName = "nuget.org" 9 | $feedURI = "https://api.nuget.org/v3/index.json" 10 | $downloadAttempts = 5 11 | $downloadRetryBackoffSeconds = 10 12 | # Set to $True to use the Extended API. 13 | $useExtendedApi = $False 14 | # Optional 15 | $feedUsername = "" 16 | $feedPassword = "" 17 | 18 | # Get space 19 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 20 | 21 | $body = @{ 22 | Id = $null 23 | FeedType = "NuGet" 24 | DownloadAttempts = $downloadAttempts 25 | DownloadRetryBackoffSeconds = $downloadRetryBackoffSeconds 26 | EnhancedMode = $useExtendedApi 27 | Name = $feedName 28 | FeedUri = $feedURI 29 | } 30 | if(-not ([string]::IsNullOrEmpty($feedUsername))) 31 | { 32 | $body.Username = $feedUsername 33 | } 34 | if(-not ([string]::IsNullOrEmpty($feedPassword))) 35 | { 36 | $body.Password = @{ 37 | HasValue = $True; 38 | NewValue = $feedPassword; 39 | }; 40 | } 41 | 42 | # Create Feed 43 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/feeds" -Body ($body | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/DeleteFeed.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $feedName = "nuget.org" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get feedID 14 | $feed = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/feeds/all" -Headers $header) | Where-Object {$_.Name -eq $feedName} 15 | $feedID = $feed.Id 16 | 17 | # Delete Feed 18 | Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/feeds/$feedID" -Headers $header -Method Delete -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/DownloadPackage.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $packageName = "packageName" 9 | $packageVersion = "1.0.0.0" 10 | $outputFolder = "/path/to/output/folder" 11 | 12 | # Get space 13 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 14 | 15 | # Get package details 16 | $package = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/packages/packages-$packageName.$packageVersion" -Headers $header) 17 | 18 | # Get package 19 | $filePath = [System.IO.Path]::Combine($outputFolder, "$($package.PackageId).$($package.Version)$($package.FileExtension)") 20 | Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/packages/$packageName.$packageVersion/raw" -Headers $header -OutFile $filePath 21 | Write-Host "Downloaded file to $filePath" -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/GetAllFeeds.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | 9 | # Get space 10 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 11 | 12 | # Get all feeds 13 | $feeds = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/feeds/all" -Headers $header) 14 | 15 | # Enumerate each feed 16 | foreach($feed in $feeds) 17 | { 18 | $feed 19 | } -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/GetAllPackageSizes.ps1: -------------------------------------------------------------------------------- 1 | $octopusApiKey = "YOUR API KEY" 2 | $octopusUrl = "YOUR URL" 3 | $header = @{ "X-Octopus-ApiKey" = $octopusApiKey } 4 | 5 | $spaceResults = Invoke-RestMethod -Method Get -Uri "$OctopusUrl/api/spaces?skip=0&take=100000" -Headers $header 6 | foreach ($space in $spaceResults.Items) 7 | { 8 | Write-Host $space.Name 9 | $spaceId = $space.id 10 | $feedList = Invoke-RestMethod -Method Get -Uri "$OctopusUrl/api/$spaceId/Feeds" -Headers $header 11 | foreach ($feed in $feedList.Items) 12 | { 13 | if ($feed.FeedType -ne "BuiltIn") 14 | { 15 | continue 16 | } 17 | 18 | $packageList = Invoke-RestMethod -Method Get -Uri "$OctopusUrl/api/$spaceId/feeds/$($feed.Id)/packages/search" -Headers $header 19 | foreach ($package in $packageList.Items) 20 | { 21 | Write-Host " $($package.Name)" 22 | $packageVersionList = Invoke-RestMethod -Method Get -Uri "$OctopusUrl/api/$spaceId/feeds/$($feed.Id)/packages/versions?packageId=$($package.Id)&skip=0&take=100000" -Headers $header 23 | foreach ($packageVersion in $packageVersionList.Items) 24 | { 25 | $sizeInKB = $packageVersion.SizeBytes / 1024 26 | Write-Host " $($packageVersion.Version) - $sizeInKB KB" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/GetFeedDetails.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $feedId = "Feeds-yourfeedid" # During deployment you can use system variable #{Octopus.Action.Package.FeedId} 9 | 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get package details 15 | $feed = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/feeds/$feedId" -Headers $header) 16 | 17 | write-host $feed.FeedUri 18 | -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/GetLatestPackageVersion.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-KEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $packageId = "your-package-id" 9 | 10 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 11 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 12 | 13 | # Get latest package version 14 | $latestPackages = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/feeds/feeds-builtin/packages/versions?packageId=$($packageId)&take=1" -Headers $header 15 | $latestPackage = $latestPackages.Items | Select-Object -First 1 16 | $latestPackage 17 | -------------------------------------------------------------------------------- /REST/PowerShell/Feeds/GetSpecificPackageVersion.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-KEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $packageId = "your-package-id" 9 | 10 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 11 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 12 | 13 | # Check for specific version of 1.0.0.6 14 | $versionRange="[1.0.0.6,1.0.0.6]" 15 | $specificVersionPackages = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/feeds/feeds-builtin/packages/versions?packageId=$($packageId)&versionRange=$versionRange&take=1" -Headers $header 16 | $specificPackage = $specificVersionPackages.Items | Select-Object -First 1 17 | $specificPackage -------------------------------------------------------------------------------- /REST/PowerShell/License/Get-LicensedTargetStatus.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | 8 | $licenseStatus = Invoke-RestMethod -Uri "$octopusUrl/api/licenses/licenses-current-status" -Headers $header 9 | 10 | $targets = $licenseStatus.Limits | Where-Object { $_.Name -eq "Targets" } 11 | 12 | $utilizedTargetCount = $targets.CurrentUsage 13 | $licensedTargetCount = $targets.EffectiveLimit 14 | 15 | if($targets.IsUnlimited) 16 | { 17 | Write-Host "Using $utilizedTargetCount targets of unlimited licensed targets." 18 | } 19 | else { 20 | Write-Host "Using $utilizedTargetCount targets of $licensedTargetCount licensed targets." 21 | } 22 | -------------------------------------------------------------------------------- /REST/PowerShell/Machines/README.md: -------------------------------------------------------------------------------- 1 | # Machines 2 | 3 | You can find scripts related to machines under the [Targets](../Targets) folder. 4 | -------------------------------------------------------------------------------- /REST/PowerShell/Miscellaneous/GetMachinesByRolesInCurrentDeployment.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | This script should run from: 3 | 4 | - A script step 5 | - That's executed on the Octopus Server 6 | - With a Window size of 1 7 | 8 | It'll create an output variable called "MachineNames" Which will have the names of the machines (in octopus, so not the same as $env:computername). 9 | 10 | To learn more about the usage of output variables read http://octopusdeploy.com/blog/fun-with-output-variables 11 | #> 12 | 13 | ##CONFIG## 14 | $Role = "" #Role you want to filter by. 15 | $OctopusAPIkey = "" #API Key to authenticate in Octopus. 16 | 17 | ##PROCESS## 18 | $OctopusURL = $OctopusParameters['Octopus.Web.BaseUrl'] 19 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 20 | 21 | $MachineIDs = ($OctopusParameters["Octopus.Environment.MachinesInRole[$Role]"]).Split(',') 22 | 23 | $machineNamesArray = @() 24 | 25 | foreach ($Id in $MachineIDs){ 26 | $MachineNamesArray += ((Invoke-WebRequest $OctopusURL/api/machines/$id -Headers $header -Method Get).content | ConvertFrom-Json | select -ExpandProperty Name) 27 | } 28 | 29 | $MachineNamesString = $machineNamesArray -join "," 30 | 31 | #Creating the Output variable 32 | Set-OctopusVariable -name "MachineNames" -value $MachineNamesString -------------------------------------------------------------------------------- /REST/PowerShell/Miscellaneous/GetOctopusServerVersion.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | $OctopusAPIkey = "" #Your Octopus API Key 3 | $OctopusURL = "" #Your Octopus Server root URL 4 | 5 | ##PROCESS## 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $ServerVersion = ((Invoke-WebRequest $OctopusURL/api -Method GET -Headers $header).content | ConvertFrom-Json).version 8 | $ServerVersion 9 | 10 | -------------------------------------------------------------------------------- /REST/PowerShell/OctopusServerNodes/DeleteAllNodes.ps1: -------------------------------------------------------------------------------- 1 | $octopusURI = "https://octopus.url" # Replace this with your octopus URL 2 | $apiKey = "API-1232" # Replace this with your API key http://docs.octopusdeploy.com/display/OD/How+to+create+an+API+key 3 | 4 | $header = @{ "X-Octopus-ApiKey" = $apiKey } 5 | 6 | $nodes = Invoke-WebRequest -Uri "$octopusURI/api/octopusservernodes" -Headers $header | ConvertFrom-Json 7 | $nodes.Items | % { 8 | $id = $_.Id 9 | Invoke-WebRequest -Uri "$octopusURI/api/octopusservernodes/$id" -Headers $header -Method Delete 10 | } 11 | -------------------------------------------------------------------------------- /REST/PowerShell/Packages/README.md: -------------------------------------------------------------------------------- 1 | # Packages 2 | 3 | You can find scripts related to packages under the [Feeds](../Feeds) folder. 4 | -------------------------------------------------------------------------------- /REST/PowerShell/ProjectGroups/ListProjectsInProjectGroup.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $projectGroupName = "Your project Group name" 9 | 10 | # Get space 11 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 12 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 13 | 14 | # Get project group 15 | $projectGroups = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/projectgroups?partialName=$([uri]::EscapeDataString($projectGroupName))&skip=0&take=100" -Headers $header 16 | $projectGroup = $projectGroups.Items | Where-Object { $_.Name -eq $projectGroupName } 17 | 18 | # Get projects 19 | $projects = @() 20 | $response = $null 21 | do { 22 | $uri = if ($response) { $octopusURL + $response.Links.'Page.Next' } else { "$octopusURL/api/$($space.Id)/projectgroups/$($projectGroup.Id)/projects" } 23 | $response = Invoke-RestMethod -Method Get -Uri $uri -Headers $header 24 | $projects += $response.Items 25 | } while ($response.Links.'Page.Next') 26 | 27 | Write-Host "Found $($projects.Count) projects in group $($projectGroupName)" -------------------------------------------------------------------------------- /REST/PowerShell/Projects/CreateProject.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $projectName = "MyProject" 9 | $projectDescription = "MyDescription" 10 | $projectGroupName = "Default project group" 11 | $lifecycleName = "Default lifecycle" 12 | 13 | # Get space 14 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 15 | 16 | # Get project group 17 | $projectGroup = (Invoke-RestMethod -Method Get "$octopusURL/api/$($space.Id)/projectgroups/all" -Headers $header) | Where-Object {$_.Name -eq $projectGroupName} 18 | 19 | # Get Lifecycle 20 | $lifeCycle = (Invoke-RestMethod -Method Get "$octopusURL/api/$($space.Id)/lifecycles/all" -Headers $header) | Where-Object {$_.Name -eq $lifecycleName} 21 | 22 | # Create project json payload 23 | $jsonPayload = @{ 24 | Name = $projectName 25 | Description = $projectDescription 26 | ProjectGroupId = $projectGroup.Id 27 | LifeCycleId = $lifeCycle.Id 28 | } 29 | 30 | # Create project 31 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/projects" -Body ($jsonPayload | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Projects/DeleteProjectByName.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $projectName = "MyProject" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get project 14 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 15 | 16 | # Delete project 17 | Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Projects/DeleteProjectsWithoutDeploymentProcess.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctopusurl" 5 | $octopusAPIKey = "API-KEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | 8 | # Get space 9 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 10 | 11 | # Get project 12 | $projects = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header 13 | 14 | # Loop through projects 15 | foreach ($project in $projects) 16 | { 17 | # Get deployment process 18 | $deploymentProcess = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/deploymentprocesses/$($project.DeploymentProcessId)" -Headers $header 19 | 20 | # Check to see if there's a process 21 | if (($null -eq $deploymentProcess.Steps) -or ($deploymentProcess.Steps.Count -eq 0)) 22 | { 23 | # Delete project 24 | Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header 25 | } 26 | } -------------------------------------------------------------------------------- /REST/PowerShell/Projects/DisableAllProjectTriggers.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $projectName = "MyProject" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get project 14 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 15 | 16 | # Get project triggers 17 | $projectTriggers = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/triggers" -Headers $header 18 | 19 | # Loop through triggers 20 | foreach ($projectTrigger in $projectTriggers.Items) 21 | { 22 | # Disable the trigger 23 | $projectTrigger.IsDisabled = $true 24 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/projecttriggers/$($projectTrigger.Id)" -Body ($projectTrigger | ConvertTo-Json -Depth 10) -Headers $header 25 | } -------------------------------------------------------------------------------- /REST/PowerShell/Projects/DisableProject.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | $projectName = "MyProject" 9 | $projectEnabled = $False 10 | 11 | # Get space 12 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 13 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 14 | 15 | # Get project 16 | $projects = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/projects?partialName=$([uri]::EscapeDataString($projectName))&skip=0&take=100" -Headers $header 17 | $project = $projects.Items | Where-Object { $_.Name -eq $projectName } 18 | 19 | # Enable/Disable project 20 | $project.IsDisabled = !$projectEnabled 21 | 22 | # Save project changes 23 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header -Body ($project | ConvertTo-Json -Depth 10) -------------------------------------------------------------------------------- /REST/PowerShell/Projects/GetLastSuccessfulDeploymentPerEnvForAllProjects.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG 2 | $octopusURL = "https://YOUR_OCTOPUS_SERVER" #Octopus URL 3 | $octopusAPIKey = "API-1234123412341234" #Octopus API Key 4 | $spaceName = "Default" 5 | 6 | ##PROCESS## 7 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 8 | 9 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 10 | $projects = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects?take=2000000" -Headers $header).items 11 | 12 | foreach ($project in $projects) 13 | { 14 | Write-Host "`nChecking Project: $($project.Name)" 15 | $ProjectDashboardReleases = (Invoke-WebRequest $octopusURL/api/progression/$($project.Id) -Method Get -Headers $header).content | ConvertFrom-Json 16 | foreach ($environment in $ProjectDashboardReleases.Environments) 17 | { 18 | $LastSuccessfulRelease = $ProjectDashboardReleases.Releases.Deployments.$($environment.Id) | ?{$_.state -eq "Success"} | select -First 1 19 | Write-Output "Last Successful Release in $($environment.Name): `t$($LastSuccessfulRelease.CompletedTime)" 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /REST/PowerShell/Projects/RenameProject.ps1: -------------------------------------------------------------------------------- 1 | 2 | $ErrorActionPreference = "Stop"; 3 | 4 | # Define working variables 5 | $octopusURL = "https://your.octopus.app" 6 | $octopusAPIKey = "API-YOURAPIKEY" 7 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 8 | $spaceName = "Default" 9 | $projectName = "MyProject" 10 | $newProjectName = "MyNewProjectName" 11 | 12 | # Get space 13 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 14 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 15 | 16 | # Get project 17 | $projects = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/projects?partialName=$([uri]::EscapeDataString($projectName))&skip=0&take=100" -Headers $header 18 | $project = $projects.Items | Where-Object { $_.Name -eq $projectName } 19 | 20 | # Set project new name 21 | $project.Name = $newProjectName 22 | 23 | # Save project changes 24 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header -Body ($project | ConvertTo-Json -Depth 10) -------------------------------------------------------------------------------- /REST/PowerShell/Projects/UpdateVCSCredsUrl.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-####" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $projectName = "Project Name" 8 | $spaceId = "Spaces-##" 9 | $gitCredId = "GitCredentials-##" # From Library > Git Credentials 10 | $gitRepoUrl = "https://github.com//.git" 11 | 12 | # Get project 13 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($spaceId)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 14 | 15 | # Change from Username/Password at the project level to a Git Credential in the library (optional, but Git Creds are much easier - can change back via UI if desired) 16 | $project.PersistenceSettings.Credentials.Type = "Reference" 17 | $project.PersistenceSettings.Credentials.PSObject.Properties.Remove("Username") 18 | $project.PersistenceSettings.Credentials.PSObject.Properties.Remove("Password") 19 | $project.PersistenceSettings.Credentials | Add-Member -NotePropertyName Id -NotePropertyValue $gitCredId 20 | 21 | # Update VCS Github repo URL 22 | $project.PersistenceSettings.Url = $gitRepoUrl 23 | 24 | # Commit changes to Octopus project 25 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($spaceId)/projects/$($project.Id)" -Headers $header -Body ($project | ConvertTo-Json -Depth 100) 26 | -------------------------------------------------------------------------------- /REST/PowerShell/Releases/DeleteReleasesForProject.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $projectName = "MyProject" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get project 14 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 15 | 16 | # Get releases for project 17 | $releases = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/releases" -Headers $header 18 | 19 | # Loop through list 20 | foreach ($release in $releases.Items) 21 | { 22 | # Delete release 23 | Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/releases/$($release.Id)" -Headers $header 24 | } -------------------------------------------------------------------------------- /REST/PowerShell/Releases/GetLastSuccessfulForProjectAndEnvironment.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG 2 | $OctopusURL = "" #Octopus URL 3 | $OctopusAPIKey = "" #Octopus API Key 4 | 5 | ##PROCESS## 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $ProjectID = $OctopusParameters['Octopus.Project.ID'] 8 | $EnvironmentID = $OctopusParameters['Octopus.Environment.ID'] 9 | 10 | $ProjectDashboardReleases = (Invoke-WebRequest $OctopusURL/api/progression/$ProjectID -Method Get -Headers $header).content | ConvertFrom-Json 11 | 12 | $LastSuccessfullRelease = $ProjectDashboardReleases.Releases.Deployments.$EnvironmentId | ?{$_.state -eq "Success"} | select -First 1 13 | 14 | $LastSuccessfullRelease.ReleaseVersion -------------------------------------------------------------------------------- /REST/PowerShell/Releases/GetLastSuccessfulForProjectAndEnvironmentAndTenant.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG 2 | $OctopusURL = "" #Octopus URL 3 | $OctopusAPIKey = "" #Octopus API Key 4 | 5 | ##PROCESS## 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $ProjectID = $OctopusParameters['Octopus.Project.ID'] 8 | $EnvironmentID = $OctopusParameters['Octopus.Environment.ID'] 9 | $TenantID = $OctopusParameters['Octopus.Deployment.Tenant.Id'] 10 | 11 | $ProjectDashboardReleases = (Invoke-WebRequest $OctopusURL/api/progression/$ProjectID -Method Get -Headers $header -UseBasicParsing).content | ConvertFrom-Json 12 | 13 | $LastSuccessfullRelease = $ProjectDashboardReleases.Releases.Deployments.$EnvironmentId | ?{$_.state -eq "Success"} | ?{$_.TenantId -eq "$TenantID"} | select -First 1 14 | 15 | $LastSuccessfullRelease.ReleaseVersion 16 | -------------------------------------------------------------------------------- /REST/PowerShell/Releases/GetReleaseDetails.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $projectName = "MyProject" 8 | $releaseVersion = "1.0.0.0" 9 | $spaceName = "Default" 10 | 11 | # Get space 12 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 13 | $space = $spaces.Items | Where-Object { $_.Name -eq $spaceName } 14 | 15 | # Get project 16 | $projects = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/projects?partialName=$([uri]::EscapeDataString($projectName))&skip=0&take=100" -Headers $header 17 | $project = $projects.Items | Where-Object { $_.Name -eq $projectName } 18 | 19 | # Get release 20 | $releases = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/releases" -Headers $header 21 | $release = $releases.Items | Where-Object { $_.Version -eq $releaseVersion } 22 | 23 | # Display release packages 24 | $release.SelectedPackages | Format-List 25 | 26 | # Display release 27 | $release -------------------------------------------------------------------------------- /REST/PowerShell/Releases/Release_UpdateReleaseNotes.ps1: -------------------------------------------------------------------------------- 1 | #This script will update the release notes of the current release 2 | 3 | $OctopusURL = "" #URL of Octopus Server 4 | $OctopusAPIKey = "" #API Key to authenticate to Octopus Server 5 | $newreleasenotes = "" #New release note for the current Release 6 | 7 | $header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } 8 | $releaseurl = $OctopusParameters["Octopus.Web.ReleaseLink"].Replace("/app#","api") 9 | 10 | $release = Invoke-WebRequest $OctopusURL/$releaseurl -Headers $header | select -ExpandProperty Content | ConvertFrom-Json 11 | 12 | $release.ReleaseNotes = $newreleasenotes 13 | 14 | Invoke-WebRequest $OctopusURL/$releaseurl -Method Put -Headers $header -Body ($release | ConvertTo-Json) -------------------------------------------------------------------------------- /REST/PowerShell/Releases/UpdateReleaseVariableSnapshot.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $projectName = "MyProject" 8 | $releaseVersion = "1.0.0.0" 9 | $channelName = "Default" 10 | $spaceName = "default" 11 | 12 | # Get space 13 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 14 | 15 | # Get project 16 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 17 | 18 | # Get channel 19 | $channel = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/channels" -Headers $header).Items | Where-Object {$_.Name -eq $channelName} 20 | 21 | # Get release 22 | $release = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/releases" -Headers $header).Items | Where-Object {$_.Version -eq $releaseVersion -and $_.ChannelId -eq $channel.Id} 23 | 24 | # Update the variable snapshot 25 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/releases/$($release.Id)/snapshot-variables" -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Runbooks/CreateRunbook.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $projectName = "MyProject" 9 | $runbookName = "MyRunbook" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get project 15 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 16 | 17 | # Create json payload 18 | $jsonPayload = @{ 19 | Name = $runbookName 20 | ProjectId = $project.Id 21 | EnvironmentScope = "All" 22 | RunRetentionPolicy = @{ 23 | QuantityToKeep = 100 24 | ShouldKeepForever = $false 25 | } 26 | } 27 | 28 | # Create the runbook 29 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/runbooks" -Body ($jsonPayload | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Runbooks/DeleteRunbook.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "Your API Key" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Space Name" 8 | $projectName = "Project Name" 9 | $runbookName = "Runbook Name" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get project 15 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 16 | 17 | # Get runbook 18 | $runbook = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/runbooks/all" -Headers $header) | Where-Object {$_.Name -eq $runbookName -and $_.ProjectId -eq $project.Id} 19 | 20 | # Delete the runbook 21 | Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/runbooks/$($runbook.Id)" -Headers $header 22 | -------------------------------------------------------------------------------- /REST/PowerShell/Runbooks/PublishRunbook.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $projectName = "MyProject" 9 | $runbookName = "MyRunbook" 10 | $snapshotName = "Snapshot 9PNENH6" 11 | 12 | # Get space 13 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 14 | 15 | # Get project 16 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 17 | 18 | # Get runbook 19 | $runbook = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/runbooks" -Headers $header).Items | Where-Object {$_.Name -eq $runbookName} 20 | 21 | # Get the runbook process 22 | $runbookSnapshot = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)/runbookSnapshots" -Headers $header).Items | Where-Object {$_.Name -eq $snapshotName} 23 | 24 | # Publish the snapshot 25 | $runbook.PublishedRunbookSnapshotId = $runbookSnapshot.Id 26 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/runbooks/$($runbook.Id)" -Body ($runbook | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/ScriptModules/AddScriptModuleToProject.ps1: -------------------------------------------------------------------------------- 1 | # This script connects a Script Module to a Project 2 | 3 | $ErrorActionPreference = "Stop"; 4 | 5 | # Define working variables 6 | $octopusURL = "https://YOUR_OCTOPUS_URL" 7 | $octopusAPIKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 8 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 9 | $projectName = "Some Project" 10 | $scriptModuleName = "Some script module" 11 | $spaceName = "Some Space" 12 | 13 | # Get space 14 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 15 | 16 | # Get project 17 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 18 | 19 | # Get script module 20 | $scriptModule = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/libraryvariablesets/all" -Headers $header) | Where-Object {$_.Name -eq $scriptModuleName} 21 | 22 | # Add the script module 23 | $project.IncludedLibraryVariableSetIds += $scriptModule.Id 24 | 25 | # Update the project 26 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header -Body ($project | ConvertTo-Json -Depth 10) -------------------------------------------------------------------------------- /REST/PowerShell/Spaces/DeleteSpace.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | 8 | $spaceName = "New Space" 9 | 10 | Write-Host "Getting space '$spaceName'" 11 | $spaces = (Invoke-WebRequest $octopusURL/api/spaces?take=21000 -Headers $header -Method Get -ErrorVariable octoError).Content | ConvertFrom-Json 12 | 13 | $space = $spaces.Items | Where-Object Name -eq $spaceName 14 | 15 | if ($null -eq $space) { 16 | Write-Host "Could not find space with name '$spaceName'" 17 | exit 18 | } 19 | 20 | $space.TaskQueueStopped = $true 21 | $body = $space | ConvertTo-Json 22 | 23 | Write-Host "Stopping space task queue" 24 | (Invoke-WebRequest $octopusURL/$($space.Links.Self) -Headers $header -Method PUT -Body $body -ErrorVariable octoError) | Out-Null 25 | 26 | Write-Host "Deleting space" 27 | (Invoke-WebRequest $octopusURL/$($space.Links.Self) -Headers $header -Method DELETE -ErrorVariable octoError) | Out-Null 28 | 29 | Write-Host "Action Complete" -------------------------------------------------------------------------------- /REST/PowerShell/StepTemplates/DeleteLibraryStepTemplateByName.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | $OctopusAPIkey = "" #Octopus API Key 3 | $OctopusURL = "" #Octopus URL 4 | $TemplateName = "" #Template to delete 5 | 6 | ##PROCESS## 7 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 8 | 9 | $alltemplates = (Invoke-WebRequest $OctopusURL/api/actiontemplates/all -Method Get -Headers $header).content | ConvertFrom-Json 10 | 11 | $TemplateToDelete = $alltemplates | ?{$_.Name -eq $TemplateName} 12 | 13 | If(!([string]::IsNullOrEmpty($TemplateToDelete))){ 14 | Invoke-WebRequest ($OctopusURL + $TemplateToDelete.links.self) -Method Delete -Headers $header 15 | } 16 | else{ 17 | Write-Output "No step template found with the name: $TemplateName" 18 | } 19 | -------------------------------------------------------------------------------- /REST/PowerShell/StepTemplates/ExportStepTemplatesToFiles.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | 9 | # Get space 10 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object { $_.Name -eq $spaceName } 11 | 12 | # Get step templates 13 | $templates = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/actiontemplates?take=250" -Headers $header) 14 | 15 | mkdir "$PSScriptRoot/step-templates" 16 | 17 | $templates.Items | ForEach-Object { 18 | $template = $_ 19 | $name = $template.Name.Replace(" ", "-") 20 | Write-Host "Writing $PSScriptRoot/step-templates/$name.json" 21 | ($template | ConvertTo-Json) | Out-File -FilePath "$PSScriptRoot/step-templates/$name.json" 22 | } -------------------------------------------------------------------------------- /REST/PowerShell/StepTemplates/Initialize-StepTemplateControlTypes.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = 'Stop'; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.server" 5 | $octopusAPIKey = "API-KEY" 6 | 7 | function Invoke-PagedOctoGet($uriFragment) 8 | { 9 | $items = @() 10 | $response = $null 11 | do { 12 | $uri = if ($response) { $octopusURL + $response.Links.'Page.Next' } else { "$octopusURL/$uriFragment" } 13 | $response = Invoke-RestMethod -Method Get -Uri $uri -Headers @{ "X-Octopus-ApiKey" = $octopusAPIKey } 14 | $items += $response.Items 15 | } while ($response.Links.'Page.Next') 16 | 17 | $items 18 | } 19 | 20 | $stepTemplates = Invoke-PagedOctoGet "api/actiontemplates" | Where-Object { $_.CommunityActionTemplateId -eq $null } 21 | foreach ($stepTemplate in $stepTemplates) { 22 | foreach ($parameter in $stepTemplate.Parameters) { 23 | if (!($parameter.DisplaySettings.PSObject.Properties.Name -match "Octopus.ControlType")) { 24 | $parameter.DisplaySettings = @{'Octopus.ControlType' = 'SingleLineText'} 25 | 26 | Invoke-RestMethod ` 27 | -Method Put ` 28 | -Uri "$octopusURL/api/actiontemplates/$($stepTemplate.Id)" ` 29 | -Headers @{ "X-Octopus-ApiKey" = $octopusAPIKey } ` 30 | -Body ($stepTemplate | ConvertTo-Json -Depth 5) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/AddRoleToTarget.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $machineName = "MyMachine" 9 | $targetRole = "MyRole" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get machine 15 | $machine = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$_.Name -eq $machineName} 16 | 17 | # Add target role 18 | $machine.roles += ($targetRole) 19 | 20 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)" -Body ($machine | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Targets/ChangeTargetMachinePolicy.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $machineName = "MyMachine" 9 | $machinePolicyName = "MyPolicy" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get machine list 15 | $machine = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$_.Name -eq $machineName} 16 | 17 | # Get machine policy 18 | $machinePolicy = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machinepolicies/all" -Headers $header) | Where-Object {$_.Name -eq $machinePolicyName} 19 | 20 | # Update machine object 21 | $machine.MachinePolicyId = $machinePolicy.Id 22 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)" -Body ($machine | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Targets/CheckForTentacleUpgrades.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app/api" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "Default" 8 | 9 | # Get space id 10 | $spaces = Invoke-RestMethod -Method Get -Uri "$octopusURL/spaces/all" -Headers $header -ErrorVariable octoError 11 | $space = $spaces | Where-Object { $_.Name -eq $spaceName } 12 | Write-Host "Using Space named $($space.Name) with id $($space.Id)" 13 | 14 | # Create space specific url 15 | $octopusSpaceUrl = "$octopusURL/$($space.Id)" 16 | 17 | # Get tentacles 18 | $targets = Invoke-RestMethod -Method Get -Uri "$octopusSpaceUrl/machines/all" -Headers $header -ErrorVariable octoError 19 | $workers = Invoke-RestMethod -Method Get -Uri "$octopusSpaceUrl/workers/all" -Headers $header -ErrorVariable octoError 20 | 21 | ($targets + $workers) 22 | | Where-Object { $_.Endpoint -and $_.Endpoint.TentacleVersionDetails } 23 | | ForEach-Object { 24 | Write-Host "Checking Tentacle version for $($_.Name)" 25 | $details = $_.Endpoint.TentacleVersionDetails 26 | 27 | Write-Host "`tTentacle status: $($_.HealthStatus)" 28 | Write-Host "`tCurrent version: $($details.Version)" 29 | Write-Host "`tUpgrade suggested: $($details.UpgradeSuggested)" 30 | Write-Host "`tUpgrade required: $($details.UpgradeRequired)" 31 | } -------------------------------------------------------------------------------- /REST/PowerShell/Targets/CheckHealthOfSpecificTargets.ps1: -------------------------------------------------------------------------------- 1 | #NOTE: This script does not RUN a health check, it only checks the current status of a machine from the latest health check. 2 | 3 | # Define working variables 4 | $OctopusURL = "https://" 5 | $OctopusAPIKey = "API-" 6 | $Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } 7 | $SpaceName = "" 8 | $MachineIDs = @("Machines-501","Machines-991") #comma separated list of machine ID's that you'd like to check the latest health status of. 9 | 10 | $Space = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/spaces/all" -Headers $Header) | Where-Object { $_.Name -eq $SpaceName } 11 | 12 | Write-Host "`r`n" 13 | foreach ($machineID in $MachineIDs){ 14 | $Machine = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.id)/machines/$($machineID)" -Headers $Header) 15 | Write-Host "Machine: $($machine.Name)($($machineID)) `r`n| Disabled: $($machine.IsDisabled) `r`n| Health Status: $($machine.HealthStatus) `r`n| Status Summary: $($machine.StatusSummary)`r`n`r`n" 16 | } 17 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/DeleteMachinesByEnvironment.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl/api" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $environmentName = "MyEnvironment" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get Environment ID 14 | $environmentID = ((Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/environments/all" -Headers $header) | Where-Object {$_.Name -eq $environmentName}).Id 15 | 16 | # Get machine list 17 | $machines = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$environmentID -in $_.EnvironmentIds} 18 | 19 | # Loop through list 20 | foreach ($machine in $machines) 21 | { 22 | # Remove machine 23 | Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)" -Headers $header 24 | } 25 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/DeleteMachinesByRole.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $role = "MyRole" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get machine list 14 | $machines = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$role -in $_.Roles} 15 | 16 | # Loop through list 17 | foreach ($machine in $machines) 18 | { 19 | # Remove machine 20 | Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)" -Headers $header 21 | } -------------------------------------------------------------------------------- /REST/PowerShell/Targets/DeleteTargetByName.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl/api" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $machineName = "MachineName" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get machine list 14 | $targetList = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines?name=$machineName&skip=0&take=1000" -Headers $header) 15 | 16 | # Loop through list 17 | foreach ($target in $targetList.Items) 18 | { 19 | if ($target.Name -eq $machineName) 20 | { 21 | $targetId = $target.Id 22 | Write-Highlight "Deleting the target $targetId because the name matches the machineName" 23 | 24 | $deleteResponse = (Invoke-RestMethod "$OctopusUrl/api/$($space.Id)/machines/$targetId" -Headers $header -Method Delete) 25 | 26 | Write-Host "Delete Response $deleteResponse" 27 | break 28 | } 29 | } -------------------------------------------------------------------------------- /REST/PowerShell/Targets/DiscoverTentacle.ps1: -------------------------------------------------------------------------------- 1 | #Config 2 | $OctopusAPIkey = "" #API Key to authenticate in Octopus 3 | $OctopusURL = "" #Octopus server url 4 | 5 | $TentacleURL = "" #Tentacle URL that you'll normally use on the Web UI for the discovery 6 | $TentaclePort = "" #Tentacle Port 7 | 8 | ##Process 9 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 10 | 11 | $DiscoverData = Invoke-RestMethod "$OctopusURL/api/machines/discover?host=$TentacleURL&port=$TentaclePort&type=TentaclePassive" -Method Get -Headers $header 12 | 13 | #$DiscoverData.Endpoint will hold the Tentacle URI and Thumbprint needed to create the Tentacle 14 | 15 | #$DiscoverDate.Endpoint.URI 16 | #$DiscoverData.Endpoint.Thumbprint -------------------------------------------------------------------------------- /REST/PowerShell/Targets/FindMachineMatchingUri.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://your.octopus.app" 5 | $octopusAPIKey = "API-YOURKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | 8 | $machineUri = "http.yourhost.com" 9 | 10 | # Get space 11 | $spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?skip=0&take=100" -Headers $header 12 | 13 | # Loop through each space 14 | foreach ($space in $spaces.Items) { 15 | Write-Host "Checking space $($space.Name) ($($space.Id))" 16 | $machines = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/machines?skip=0&take=1000" -Headers $header 17 | $matchingMachine = $machines.Items | Where-Object { $_.Uri -like "*$machineUri*" } | Select-Object -First 1 18 | if($null -ne $matchingMachine) { 19 | Write-Host "Found matching machine $($matchingMachine.Name) ($($matchingMachine.Id))" -ForegroundColor Yellow 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/Get-MachineCount.ps1: -------------------------------------------------------------------------------- 1 | #This script is for all pre-Spaces Octopus servers. This will run for the default space only for versions with Spaces 2 | 3 | $OctopusUrl = "" # Octopus URL 4 | $APIKey = "" # API Key that can read the number of machines 5 | 6 | # Authenticating to the API 7 | $header = @{ "X-Octopus-ApiKey" = $APIKey } 8 | 9 | # Getting the number of active deployment targets 10 | Write-Host "Getting list of machines: $OctopusUrl/api/machines?skip=0&take=100000" 11 | $Machines = (Invoke-RestMethod "$OctopusUrl/api/machines?skip=0&take=100000" -Headers $header | Select-Object -ExpandProperty TotalResults) 12 | Write-Host "There are $Machines Deployment Targets in this Octopus Instance" -------------------------------------------------------------------------------- /REST/PowerShell/Targets/Get-RecentDeploymentsForMachines.ps1: -------------------------------------------------------------------------------- 1 | # Define Octopus variables 2 | $octopusURL = "https://youroctopusserver" 3 | $octopusAPIKey = "API-KEY" 4 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 5 | $spaceName = "Default" 6 | 7 | # Get space 8 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 9 | 10 | # Get machine details 11 | $machines = @() 12 | $response = $null 13 | do { 14 | $uri = if ($response) { $octopusURL + $response.Links.'Page.Next' } else { "$octopusURL/api/$($space.Id)/machines" } 15 | $response = Invoke-RestMethod -Method Get -Uri $uri -Headers $header 16 | $machines += $response.Items 17 | } while ($response.Links.'Page.Next') 18 | 19 | foreach ($machine in $machines) { 20 | $machineTasks = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)/tasks" -Headers $header).Items 21 | if ($machineTasks.Count -gt 0) { 22 | $machine | Add-Member LastDeployment $machineTasks[0].Description 23 | $machine | Add-Member LastDeploymentQueueTime $machineTasks[0].QueueTime 24 | } 25 | } 26 | 27 | $machines | Select-Object Id, Name, Status, LastDeployment, LastDeploymentQueueTime | Format-Table 28 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/GetMachineEnvironments.ps1: -------------------------------------------------------------------------------- 1 | ###CONFIG### 2 | $APIKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXX" #API Key to auth agains the Octopus API 3 | $OctopusURL = "https://octopus.url" #Base URL of your Octopus instance. 4 | 5 | ###PROCESS## 6 | $header = @{ "X-Octopus-ApiKey" = $APIKey } 7 | $MachineID = $OctopusParameters['Octopus.Machine.ID'] 8 | $EnvironmentNames = @() 9 | 10 | $AllEnvironments = (Invoke-WebRequest $OctopusURL/api/environments/all -Headers $header).content | ConvertFrom-Json 11 | 12 | $machine = (Invoke-WebRequest $OctopusURL/api/machines/$MachineID -Headers $header).content | ConvertFrom-Json 13 | 14 | foreach ($envID in $machine.environmentIDs){ 15 | $env = $AllEnvironments | ?{$_.id -eq $envID} 16 | $EnvironmentNames += $env.name 17 | } 18 | 19 | #This variable contains an array with the names of the environments where this machine is on 20 | $EnvironmentNames -------------------------------------------------------------------------------- /REST/PowerShell/Targets/GetMachinesInCurrentEnvironmentOfSpecificRole.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | $APIKey = "" #Octopus API. You might wanna create a service account that can only read (all) environments, then create an API key for it and use that Key. 3 | $Role = "" #Role you are looking for 4 | 5 | ##PROCESS## 6 | $OctopusURL = $OctopusParameters['Octopus.Web.BaseUrl'] 7 | $EnvironmentID = $OctopusParameters['Octopus.Environment.Id'] 8 | $header = @{ "X-Octopus-ApiKey" = $APIKey } 9 | 10 | $environment = (Invoke-WebRequest "$OctopusURL/api/environments/$EnvironmentID" -Headers $header).content | ConvertFrom-Json 11 | 12 | $environmentMachines = $Environment.Links.Machines.Split("{")[0] 13 | 14 | $machines = ((Invoke-WebRequest ($OctopusURL + $environmentMachines) -Headers $header).content | ConvertFrom-Json).items 15 | 16 | $MachinesInRole = $machines | ?{$Role -in $_.Roles} 17 | 18 | ##OUTPUT## 19 | 20 | #Name of machines in Octopus 21 | $MachinesInRole.Name 22 | 23 | #URI of machines 24 | $MachinesInRole.URI 25 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/GetTargetsPerSpace.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $OctopusUrl = "https://youroctourl" # Octopus URL 5 | $APIKey = "API-YOURAPIKEY" # API Key that can read the number of machines 6 | $header = @{ "X-Octopus-ApiKey" = $APIKey } 7 | 8 | # Get list of Spaces 9 | $spaces = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) 10 | 11 | # Getting the deployment targets in each space 12 | Foreach ($space in $spaces) { 13 | $spaceid = "$($space.id)" 14 | $spacename = "$($space.name)" 15 | If ($spacename -ne "Private") 16 | { 17 | write-host "$($spaceid) ($($spacename))" 18 | $machines = (Invoke-RestMethod -Method Get -Uri "$OctopusUrl/api/$($spaceid)/machines?skip=0&take=100000" -Headers $header) 19 | $items = $machines.items 20 | Foreach ($item in $items) { 21 | $machineid = $($item.id) 22 | $machinename = $($item.name) 23 | write-host "$($machineid) `t($($machinename)) - $OctopusUrl/api/$($spaceid)/infrastructure/machines/$($machineid)" 24 | } 25 | } 26 | write-host "---" 27 | } 28 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/ListMachinesWithUpgradeStatus.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG## 2 | $OctopusAPIkey = "" #Octopus API Key 3 | $OctopusURL = "" #Octopus URL 4 | 5 | ##PROCESS## 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | 8 | $allMachines = (Invoke-WebRequest $OctopusURL/api/machines/all -Method Get -Headers $header -UseBasicParsing).content | ConvertFrom-Json 9 | $healthyMachines = $allMachines | ? {$_.HealthStatus -eq "Healthy"} 10 | 11 | $healthyMachines | %{ "Machine $($_.Name): UpgradeSuggested=$($_.Endpoint.TentacleVersionDetails.UpgradeSuggested), UpgradeRequired=$($_.Endpoint.TentacleVersionDetails.UpgradeRequired)"} 12 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/RemoveRoleFromTarget.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $machineName = "MyMachine" 9 | $targetRole = "MyRole" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get machine 15 | $machine = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$_.Name -eq $machineName} 16 | 17 | # Remove target role 18 | $machine.Roles = $machine.Roles | Where-Object { $_ -ne $targetRole } 19 | 20 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)" -Body ($machine | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Targets/Targets_Delete.ps1: -------------------------------------------------------------------------------- 1 | # Data 2 | $OctopusURL = "" #Octopus Root URL 3 | $OctopusAPIKey = "" #Your Octopus API Key 4 | $MachineID = "" #The ID of the machine you want to delete. e.g "Machines-1" 5 | 6 | # Delete function 7 | Function Delete-OctopusTarget([string]$ID) { 8 | return Invoke-RestMethod -Uri "$OctopusUrl/api/machines/$ID`?apiKey=$OctopusApiKey" -Method Delete 9 | } 10 | 11 | # Invoke delete function 12 | Delete-OctopusTarget -ID $MachineID 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /REST/PowerShell/Targets/UpdateMachineProxy.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://mysite.octopus.app" 5 | $octopusAPIKey = "API-MYAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $machineName = "mymachinename" 9 | $machineProxyName = "myproxyname" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get machine list 15 | $machine = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$_.Name -eq $machineName} 16 | 17 | # Get specified proxy ID 18 | $machineProxy = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/proxies/all" -Headers $header) | Where-Object { $_.Name -eq $machineProxyName } 19 | 20 | # Update machine object 21 | $machine.Endpoint.ProxyId = $machineProxy.Id 22 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/machines/$($machine.Id)" -Body ($machine | ConvertTo-Json -Depth 10) -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Targets/UpgradeCalamari.ps1: -------------------------------------------------------------------------------- 1 | Add-Type -Path "" # Path to Newtonsoft.Json.dll 2 | Add-Type -Path "" # Path to Octopus.Client.dll 3 | 4 | $OctopusURL = "" #Octopus URL 5 | $OctopusAPIKey = "" # Octopus API Key 6 | $MachineName = "" #Machine Display Name 7 | 8 | $endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusURL,$OctopusAPIKey 9 | $repository = new-object Octopus.Client.OctopusRepository $endpoint 10 | $findmachine = $repository.Machines.FindByName("$MachineName") 11 | $machineid = $findmachine.id 12 | 13 | $header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } 14 | 15 | $body = @{ 16 | Name = "UpdateCalamari" 17 | Description = "Updating calamari on $MachineName" 18 | Arguments = @{ 19 | Timeout= "00:05:00" 20 | MachineIds = @($machineId) #$MachinID could contain an array of machines too 21 | } 22 | } | ConvertTo-Json 23 | 24 | Invoke-RestMethod $OctopusURL/api/tasks -Method Post -Body $body -Headers $header -------------------------------------------------------------------------------- /REST/PowerShell/Targets/UpgradeTargets.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $machineNames = @("MyMachine") 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get machine list 14 | $machines = @() 15 | foreach ($machineName in $machineNames) 16 | { 17 | # Get machine 18 | $machine = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/machines/all" -Headers $header) | Where-Object {$_.Name -eq $machineName} 19 | 20 | # Add to list 21 | $machines += $machine.Id 22 | } 23 | 24 | # Build json payload 25 | $jsonPayload = @{ 26 | Name = "Upgrade" 27 | Arguments = @{ 28 | MachineIds = $machines 29 | } 30 | Description = "Upgrade machines" 31 | SpaceId = $space.Id 32 | } 33 | 34 | # Initiate upgrade 35 | Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/tasks" -Headers $header -Body ($jsonPayload | ConvertTo-Json -Depth 10) -------------------------------------------------------------------------------- /REST/PowerShell/Tasks/ReRunSyncSecurityGroups.ps1: -------------------------------------------------------------------------------- 1 | $OctopusServerUrl = "" #PUT YOUR SERVER LOCATION HERE. (e.g. http://localhost) 2 | $ApiKey = "" #PUT YOUR API KEY HERE 3 | $taskname = "SynchronizeExternalSecurityGroupsForUsers" #IF YOU WANT TO RUN A DIFFERENT TASK, MODIFY THIS VARIABLE 4 | 5 | $task = Invoke-RestMethod -Method "get" "$OctopusServerUrl/api/tasks?take=1&skip=0&name=$($taskname)&spaces=all&includeSystem=true" -Headers @{"X-Octopus-ApiKey" = $ApiKey } 6 | $rerunurl = $task.Items[0].Links.Rerun 7 | Invoke-RestMethod -Method "POST" "$OctopusServerUrl$($rerunurl)" -Headers @{"X-Octopus-ApiKey" = $ApiKey } 8 | -------------------------------------------------------------------------------- /REST/PowerShell/Teams/AddExternalRoleToTeam.ps1: -------------------------------------------------------------------------------- 1 | # This script will add the specified external role to a team 2 | # External roles are used by authentication providers which support groups 3 | # to automatically place users into a group when they are created 4 | 5 | $OctopusURL = "" # URL of Octopus Server 6 | $OctopusAPIKey = "" # API Key to authenticate to Octopus Server 7 | $TeamName = "Octopus Administrators" 8 | $ExternalRoleId = "NewRoleId" 9 | $ExternalRoleDescription = "New role description" 10 | $header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } 11 | 12 | #get the teams 13 | $progressPreference = 'silentlyContinue' 14 | $teams = Invoke-WebRequest "$OctopusURL/api/teams" -Headers $header | select -ExpandProperty Content | ConvertFrom-Json 15 | $team = $teams.Items | Where-Object { $_.Name -eq $TeamName } 16 | 17 | $team.ExternalSecurityGroups += @{ 18 | DisplayIdAndName = $true 19 | DisplayName = $ExternalRoleDescription 20 | Id = $ExternalRoleId 21 | } 22 | 23 | Invoke-WebRequest "$OctopusURL/api/teams/$($team.Id)" -Method PUT -Headers $header -Body ($team | ConvertTo-Json) 24 | -------------------------------------------------------------------------------- /REST/PowerShell/Teams/CreateTeam.ps1: -------------------------------------------------------------------------------- 1 | $OctopusServerUrl = "https://" 2 | $ApiKey = "" 3 | 4 | #Plug in the desired values for your team here or substitute a JSON from an example creation that you would like to build from. 5 | $json = ' 6 | { 7 | "Id": null, 8 | "Name": "TestCreate3", 9 | "SpaceId": "Spaces-1", 10 | "ExternalSecurityGroups": [], 11 | "MemberUserIds": [], 12 | "CanBeDeleted": true, 13 | "CanBeRenamed": true, 14 | "CanChangeMembers": true, 15 | "CanChangeRoles": true, 16 | "Links": null, 17 | "Description": "" 18 | } 19 | ' 20 | Invoke-RestMethod -Method "POST" "$OctopusServerUrl/api/teams" -Headers @{"X-Octopus-ApiKey" = $ApiKey } -body $json 21 | -------------------------------------------------------------------------------- /REST/PowerShell/Teams/FindTeamsWithUserRole.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $spaceName = "default" 8 | $userRoleName = "Deployment creator" 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get user role 14 | $userRole = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/userroles/all" -Headers $header) | Where-Object {$_.Name -eq $userRoleName} 15 | 16 | # Get teams collection 17 | $teams = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/teams/all" -Headers $header 18 | 19 | # Loop through teams 20 | $teamNames = @() 21 | foreach ($team in $teams) 22 | { 23 | # Get scoped roles for team 24 | $scopedUserRole = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/teams/$($team.Id)/scopeduserroles" -Headers $header).Items | Where-Object {$_.UserRoleId -eq $userRole.Id} 25 | 26 | # Check for null 27 | if ($null -ne $scopedUserRole) 28 | { 29 | # Add to teams 30 | $teamNames += $team.Name 31 | } 32 | } 33 | 34 | # Loop through results 35 | Write-Host "The following teams are using role $($userRoleName):" 36 | foreach ($teamName in $teamNames) 37 | { 38 | Write-Host "$teamName" 39 | } -------------------------------------------------------------------------------- /REST/PowerShell/Teams/TestActiveDirectoryIntegration.ps1: -------------------------------------------------------------------------------- 1 | # This will test your active directory integration within Octopus Deploy itself. 2 | $octopusURL = "https://yourinstance.com" 3 | $octopusAPIKey = "YOUR API KEY" 4 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 5 | 6 | $teamNameToLookUp = "NAME TO SEARCH FOR" # Dev 7 | $expectedMatch = "EXACT MATCH TO FIND" # Developers 8 | 9 | $directoryServicesResults = Invoke-RestMethod -Method GET -Uri "$octopusURL/api/externalgroups/directoryServices?partialName=$([System.Web.HTTPUtility]::UrlEncode($teamNameToLookUp))" -Headers $header 10 | 11 | $teamId = $null 12 | foreach ($teamFound in $directoryServicesResults) 13 | { 14 | If ($teamFound.DisplayName -eq $expectedMatch) 15 | { 16 | $teamId = $teamFound.Id 17 | break 18 | } 19 | } 20 | 21 | if ($null -ne $teamId) 22 | { 23 | Write-Host "Successfully found the team $teamNameToLookUp matching $expectedMatch. The id is $teamId" 24 | } 25 | else 26 | { 27 | Write-Host "Unable to find team $teamNameToLookUp matching $expectedMatch" 28 | } -------------------------------------------------------------------------------- /REST/PowerShell/Tenants/AddTenantTagToTenant.ps1: -------------------------------------------------------------------------------- 1 | $OctopusServerUrl = "https://" #PUT YOUR SERVER LOCATION HERE. (e.g. http://localhost) 2 | $ApiKey = "API-" #PUT YOUR API KEY HERE 3 | $SpaceName = "Default" #PUT THE NAME OF THE SPACE THAT HOUSES THE TENANTS HERE 4 | $spaceId = ((Invoke-RestMethod -Method Get -Uri "$OctopusServerUrl/api/spaces/all" -Headers @{"X-Octopus-ApiKey" = "$ApiKey" }) | Where-Object {$_.Name -eq $spaceName}).Id 5 | 6 | $listOfTenants = "TenantOne","TenantTwo" #PUT TENANTS THAT NEED TAGS ADDED TO THEM HERE 7 | $tagstoAdd = "Test Set/Blah","Test Set/Second Blah","Soft Drink Companies/Soft Drink Companies" #PUT TAGSET/TAG HERE TO ADD TO TENANTS ABOVE 8 | 9 | foreach ($tenant in $listOfTenants){ 10 | $tenantsSearch = (Invoke-RestMethod -Method Get -Uri "$OctopusServerUrl/api/$($spaceid)/tenants?name=$tenant" -Headers @{"X-Octopus-ApiKey" = "$ApiKey" }) 11 | $tenant = $tenantsSearch.Items | Select-Object -First 1 12 | foreach ($tag in $tagstoAdd){ 13 | $tenant.TenantTags += $tag 14 | } 15 | 16 | Invoke-RestMethod -Method PUT -Uri "$OctopusServerUrl/api/$($spaceid)/tenants/$($tenant.Id)" -Headers @{"X-Octopus-ApiKey" = "$ApiKey" } -body ($tenant | ConvertTo-Json) 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /REST/PowerShell/Tenants/RemoveAllProjectConnectionsToTenant.ps1: -------------------------------------------------------------------------------- 1 | # ==================================================== 2 | # Remove all Project connections to a Tenant 3 | # ==================================================== 4 | 5 | $ErrorActionPreference = "Stop"; 6 | 7 | # Define working variables 8 | $OctopusURL = "https://YOUR_OCTOPUS_URL" 9 | $octopusAPIKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 10 | $Header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 11 | $SpaceId = "Spaces-1" 12 | $TenantToDisconnectFromProjects = "TENANT_NAME_HERE" 13 | 14 | # Find Tenant ID 15 | $Tenant = (Invoke-RestMethod -Method GET "$OctopusURL/api/$($SpaceId)/Tenants/all" -Headers $Header) | Where-Object {$_.Name -eq $TenantToDisconnectFromProjects} 16 | 17 | $Tenant.ProjectEnvironments = @{} 18 | 19 | Invoke-RestMethod -Method PUT "$OctopusURL/api/$($SpaceId)/Tenants/$($Tenant.Id)" -Body ($Tenant | ConvertTo-Json -Depth 10) -Headers $Header 20 | Write-Host "Done!" 21 | -------------------------------------------------------------------------------- /REST/PowerShell/UserRoles/Copy-UserRole.ps1: -------------------------------------------------------------------------------- 1 | # Use this script to clone an Octopus UserRole with a new name 2 | $octopusUrl = "https://your.octopus.server" 3 | $apiKey = "API-KEY" 4 | $userRoleNameToDuplicate = "Project lead" 5 | $newRoleName = "Project lead (Safe)" 6 | 7 | $headers = @{ "X-Octopus-ApiKey" = $apiKey } 8 | $encodedName = [System.Web.HTTPUtility]::UrlEncode($userRoleNameToDuplicate) 9 | $userRole = (Invoke-RestMethod ` 10 | -Uri "$octopusUrl/api/userroles?partialName=$encodedName" ` 11 | -Headers $headers -UseBasicParsing).Items ` 12 | | Where-Object -Property Name -eq $userRoleNameToDuplicate 13 | 14 | 15 | if (!$userRole) { 16 | throw "Error: No UserRole found with name: $userRoleNameToDuplicate" 17 | } 18 | 19 | $newRole = $userRole 20 | $newRole.Name = $newRoleName 21 | 22 | Invoke-RestMethod -Uri "$octopusUrl/api/userroles" -Method Post -Headers $headers -Body ($newRole | ConvertTo-Json) 23 | -------------------------------------------------------------------------------- /REST/PowerShell/Users/CreateAPIKey.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | 8 | # UserName of the user for which the API key will be created. You can check this value from the web portal under Configuration/Users 9 | $UserName = "" 10 | 11 | #Purpose of the API Key. This field is mandatory. 12 | $APIKeyPurpose = "" 13 | 14 | # Create payload 15 | $body = @{ 16 | Purpose = $APIKeyPurpose 17 | } | ConvertTo-Json 18 | 19 | # Getting all users to filter target user by name 20 | $allUsers = (Invoke-WebRequest "$OctopusURL/api/users/all" -Headers $header -Method Get).content | ConvertFrom-Json 21 | 22 | # Getting user that owns API Key. 23 | $User = $allUsers | Where-Object { $_.username -eq $UserName } 24 | 25 | # Creating API Key 26 | $CreateAPIKeyResponse = (Invoke-WebRequest "$OctopusURL/api/users/$($User.id)/apikeys" -Method Post -Headers $header -Body $body -Verbose).content | ConvertFrom-Json 27 | 28 | # Printing new API Key 29 | Write-Output "API Key created: $($CreateAPIKeyResponse.apikey)" -------------------------------------------------------------------------------- /REST/PowerShell/Users/CreateUserInvite.ps1: -------------------------------------------------------------------------------- 1 | ### PowerShell script to get a new user invite when using user/pass auth. 2 | 3 | [String]$OctopusURL="OCTOPUS_URL" 4 | [String]$OctopusAPIKey = "API_KEY" 5 | 6 | $header = @{ 7 | "X-Octopus-ApiKey" = $OctopusAPIKey 8 | "method"="POST" 9 | "accept"="application/json" 10 | } 11 | Invoke-RestMethod -Method "Post" -Uri "$OctopusURL/api/users/invitations" -Headers $header -Body "{`"AddToTeamIds`":[],`"SpaceId`":null}" -ContentType "application/json" 12 | -------------------------------------------------------------------------------- /REST/PowerShell/Users/DeleteAPIKey.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG 2 | $OctopusURL = "" #Base url of Octopus server 3 | $APIKey = ""#API Key to authenticate to Octopus Server 4 | 5 | $UserName = "" #UserName of the user for which the API key will be created. You can check this value from the web portal under Configuration/Users 6 | $APIKeyPurpose = "" #Purpose of the API Key. This is mandatory to identify which API key will be deleted. 7 | ##PROCESS 8 | 9 | $header = @{ "X-Octopus-ApiKey" = $APIKey } 10 | 11 | $body = @{ 12 | Purpose = $APIKeyPurpose 13 | } | ConvertTo-Json 14 | 15 | #Getting all users to filter target user by name 16 | $allUsers = (Invoke-WebRequest "$OctopusURL/api/users/all" -Headers $header -Method Get).content | ConvertFrom-Json 17 | 18 | #Getting user that owns API Key that will be deleted 19 | $User = $allUsers | where{$_.username -eq $UserName} 20 | 21 | #Getting all API Keys of user 22 | $allAPIKeys = (Invoke-WebRequest "$OctopusURL/api/users/$($user.id)/ApiKeys" -Headers $header -Method Get).content | ConvertFrom-Json | select -ExpandProperty items 23 | 24 | #Getting API Key to delete 25 | $APIKeyResource = $allAPIKeys | where{$_.purpose -eq $APIKeyPurpose} 26 | 27 | #Deleting API Key 28 | Invoke-WebRequest "$OctopusURL/api/users/$($user.id)/ApiKeys/$($APIKeyResource.id)" -Headers $header -Method Delete 29 | 30 | -------------------------------------------------------------------------------- /REST/PowerShell/Users/GetUsersAPIKeyList.ps1: -------------------------------------------------------------------------------- 1 | ##Disclaimer: This script only lists the Purpuse, created date & ID of all the currently valid/registered API Keys of each user. It does not show the actual API Key value which cannot be recovered in any way after it was created. 2 | 3 | ##CONFIG## 4 | $OctopusAPIkey = ""#Your Octopus API Key 5 | $OctopusURL = ""#Your Octopus server root URL 6 | 7 | ##PROCESS## 8 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 9 | $list = @() 10 | 11 | $AllUsers = (Invoke-WebRequest $OctopusURL/api/users/all -Headers $header).content | ConvertFrom-Json 12 | 13 | foreach($user in $AllUsers){ 14 | $apikeys = $null 15 | 16 | $apikeys = (Invoke-WebRequest ($OctopusURL + $user.links.apikeys.Split('{')[0]) -Headers $header).content | ConvertFrom-Json 17 | 18 | $obj = [PSCustomObject]@{ 19 | UserName = $user.Username 20 | ID = $user.Id 21 | APIKeys = $apikeys.Items 22 | } 23 | $list += $obj 24 | } 25 | 26 | $list -------------------------------------------------------------------------------- /REST/PowerShell/Variables/AddLibraryVariableSetToSelectedProjects.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $projectName = "MyProject" 8 | $librarySetName = "MyLibrarySet" 9 | $spaceName = "MySpace" 10 | 11 | # Get space 12 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 13 | 14 | # Get project 15 | $project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} 16 | 17 | # Get library set 18 | $librarySet = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/libraryvariablesets/all" -Headers $header) | Where-Object {$_.Name -eq $librarySetName} 19 | 20 | # Add the libarary set 21 | $project.IncludedLibraryVariableSetIds += $librarySet.Id 22 | 23 | # Update the project 24 | Invoke-RestMethod -Method Put -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header -Body ($project | ConvertTo-Json -Depth 10) 25 | -------------------------------------------------------------------------------- /REST/PowerShell/Variables/AddSimpleTenantCommonVariable.ps1: -------------------------------------------------------------------------------- 1 | # Required parameters 2 | 3 | ## Instance Parameters 4 | $octopusURL = "https://octopusURL" 5 | $apiKey = "API-XXXX" 6 | $spaceId = "Spaces-ID" 7 | $variableSetId = "LibraryVariableSets-ID" 8 | 9 | ## Variable Parameters 10 | $variableName = "Tenant Common Variable" 11 | $defaultValue = "Tenant Common Value" 12 | $controlType = "SingleLineText" 13 | 14 | # Headers 15 | $headers = @{ 16 | "X-Octopus-ApiKey" = $apiKey 17 | "Content-Type" = "application/json; charset=utf-8" 18 | } 19 | 20 | # Get Var Set 21 | $variableSet = Invoke-RestMethod -Method Get -uri "$octopusUrl/api/$($spaceId)/libraryvariablesets/$($variableSetId)" -Headers $headers 22 | 23 | 24 | # Create New Template 25 | $newTemplate = @" 26 | { 27 | "DisplaySettings": { 28 | "Octopus.ControlType": "$($controlType)" 29 | }, 30 | "Name": "$($variableName)", 31 | "DefaultValue": "$($defaultValue)" 32 | } 33 | "@ 34 | 35 | # Convert $newTemplate JSON string to an object 36 | $newTemplateObj = $newTemplate | ConvertFrom-Json 37 | 38 | # Append the new template object to existing templates array 39 | $variableSet.Templates += $newTemplateObj 40 | 41 | # Update var set with PUT method 42 | Invoke-RestMethod -Method Put -Uri "$octopusUrl/api/$($spaceId)/libraryvariablesets/$($variableSetId)" -Body ($variableSet | ConvertTo-Json -Depth 10) -Headers $headers -------------------------------------------------------------------------------- /REST/PowerShell/Variables/AddSimpleTenantProjectVariable.ps1: -------------------------------------------------------------------------------- 1 | # Required parameters 2 | 3 | ## Instance Parameters 4 | $octopusURL = "https://octopusUrl" 5 | $apiKey = "API-XXXX" 6 | $spaceId = "Spaces-ID" 7 | $projectId = "Projects-ID" 8 | 9 | ## Variable Parameters 10 | $variableName = "Tenant Project Variable" 11 | $defaultValue = "Tenant Project Value" 12 | $controlType = "SingleLineText" 13 | 14 | # Headers 15 | $headers = @{ 16 | "X-Octopus-ApiKey" = $apiKey 17 | "Content-Type" = "application/json; charset=utf-8" 18 | } 19 | 20 | # Get Project 21 | $project = Invoke-RestMethod -Method Get -uri "$octopusUrl/api/$($spaceId)/projects/$($projectId)" -Headers $headers 22 | 23 | 24 | # Create New Template 25 | $newTemplate = @" 26 | { 27 | "DisplaySettings": { 28 | "Octopus.ControlType": "$($controlType)" 29 | }, 30 | "Name": "$($variableName)", 31 | "DefaultValue": "$($defaultValue)" 32 | } 33 | "@ 34 | 35 | # Convert $newTemplate JSON string to an object 36 | $newTemplateObj = $newTemplate | ConvertFrom-Json 37 | 38 | # Append the new template object to existing templates array 39 | $project.Templates += $newTemplateObj 40 | 41 | # Update project with PUT method 42 | Invoke-RestMethod -Method Put -Uri "$octopusUrl/api/$($spaceId)/projects/$($projectId)" -Body ($project | ConvertTo-Json -Depth 10) -Headers $headers -------------------------------------------------------------------------------- /REST/PowerShell/Variables/FindProjectsThatUseALibraryVariableSet.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop"; 2 | 3 | # Define working variables 4 | $octopusURL = "https://youroctourl" 5 | $octopusAPIKey = "API-YOURAPIKEY" 6 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 7 | $librarySetName = "MyLibrarySet" 8 | 9 | 10 | # Get space 11 | $space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} 12 | 13 | # Get library set reference 14 | $librarySet = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/libraryvariablesets/all" -Headers $header) | Where-Object {$_.Name -eq $librarySetName} 15 | 16 | # Get all projects 17 | $projects = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header 18 | 19 | # Loop through projects 20 | Write-Host "The following projects are using $librarySetName" 21 | foreach ($project in $projects) 22 | { 23 | # Check to see if it's using the set 24 | if ($project.IncludedLibraryVariableSetIds -contains $librarySet.Id) 25 | { 26 | Write-Host "$($project.Name)" 27 | } 28 | } -------------------------------------------------------------------------------- /REST/PowerShell/Variables/GetTenantVariablesPerProject.ps1: -------------------------------------------------------------------------------- 1 | $OctopusAPIkey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXX"#Octopus API Key 2 | 3 | $OctopusURL = "https://octopus.url"#Octopus URL 4 | 5 | $project = "Projects-31" #Name of the variable set 6 | 7 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 8 | 9 | ##Process 10 | $tenantVariables = (Invoke-WebRequest -UseBasicParsing "$OctopusURL/api/tenantvariables/all?$project" -Headers $header).content #| ConvertFrom-Json 11 | 12 | $tenantVariables 13 | -------------------------------------------------------------------------------- /REST/PowerShell/Variables/GetVariableValueFromADeployment.ps1: -------------------------------------------------------------------------------- 1 | ##CONFIG 2 | $OctopusURL = "" #Octopus URL 3 | $OctopusAPIKey = "" #Octopus API Key 4 | 5 | $DeploymentID = "" #ID of the deployment you want to get the variable from. E.g. Deployments-41 6 | $VariableName = "" #Variable name 7 | 8 | ##PROCESS## 9 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 10 | 11 | $variable = (Invoke-RestMethod -Method GET -Uri "$OctopusURL/api/variables/variableset-$DeploymentID" -Headers $header).variables | Where-Object { $_.name -eq $VariableName } 12 | 13 | $variable.value 14 | -------------------------------------------------------------------------------- /REST/PowerShell/Variables/GetVariablesFromVariableSet.ps1: -------------------------------------------------------------------------------- 1 | ##Config 2 | $OctopusAPIkey = ""#Octopus API Key 3 | 4 | $OctopusURL = ""#Octopus URL 5 | 6 | $variableSetName = "Whatever" #Name of the variable set 7 | 8 | $header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } 9 | 10 | ##Process 11 | $VariableSet = (Invoke-WebRequest "$OctopusURL/api/libraryvariablesets?contentType=Variables" -Headers $header).content | ConvertFrom-Json | select -ExpandProperty Items | ?{$_.name -eq $variableSetName} 12 | 13 | $variables = (Invoke-WebRequest "$OctopusURL/$($VariableSet.Links.Variables)" -Headers $header).content | ConvertFrom-Json | select -ExpandProperty Variables 14 | 15 | $variables #<--- Collection of variables of the variable set -------------------------------------------------------------------------------- /REST/PowerShell/Variables/Test-ReleaseNotes.ps1: -------------------------------------------------------------------------------- 1 | 2 | $ReleaseNotes = @" 3 | * [311006](https://AzureDevOps/DefaultCollection/83aaace0-5e0f-4553-b3d1-5060e8012bb0/_workitems/edit/311006): My Reports History:: error creating report but status in grid is In Progress Ready for Test 4 | * [311833](https://AzureDevOps/DefaultCollection/83aaace0-5e0f-4553-b3d1-5060e8012bb0/_workitems/edit/311833): [Generic Installer App] "Browser not supported" issue on iPhone Ready for Test 5 | * [311835](https://AzureDevOps/DefaultCollection/83aaace0-5e0f-4553-b3d1-5060e8012bb0/_workitems/edit/311835): Returns 504 error when attempting to generate for entire base Merged Into Next Release performance 6 | "@ 7 | $ReleaseNotes = $ReleaseNotes.Replace('"','\"') 8 | 9 | $ReleaseNotes 10 | 11 | octo create-release --apiKey "API-BTVNKGWA5YKPNASEMEFR8QYMGEQ" --server "https://octopus.markharrison.dev" --project "Azure CLI play" --version "1.0.1" --ignoreExisting --releaseNotes $($ReleaseNotes) -------------------------------------------------------------------------------- /REST/bash/Feeds/PushPackage.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Define working variables 4 | octopusURL="https://octopus.app" 5 | octopusAPIKey="API-" 6 | spaceName="Default" 7 | packageFile="/path/to/file" 8 | 9 | # Get space ID 10 | spaceId=$(curl -s -H "X-Octopus-ApiKey: $octopusAPIKey" "$octopusURL/api/spaces/all" | jq -r ".[] | select(.Name == \"$spaceName\") | .Id") 11 | 12 | if [ -z "$spaceId" ]; then 13 | echo "Error: Could not find space with name $spaceName" 14 | exit 1 15 | fi 16 | 17 | # Upload package 18 | response=$(curl -s -w "%{http_code}" -o /dev/null -X POST "$octopusURL/api/$spaceId/packages/raw?replace=false" \ 19 | -H "X-Octopus-ApiKey: $octopusAPIKey" \ 20 | -F "fileData=@$packageFile") 21 | 22 | if [ "$response" -ne 201 ]; then 23 | echo "Error: Failed to upload package" 24 | exit 1 25 | fi 26 | 27 | echo "Package uploaded successfully" 28 | -------------------------------------------------------------------------------- /REST/bash/Tenants/UpdateTenantTagSetValue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define working variables 4 | octopusUrl="https://your.octopus.app" 5 | octopusApiKey="API-Key" 6 | spaceName="Default" 7 | tenantName="TenantName" 8 | oldTagValue="9.0.3" 9 | newTagValue="12.0.4" 10 | 11 | # Get Space 12 | spaces=$(curl -s -H "X-Octopus-ApiKey: $octopusApiKey" -X GET "$octopusUrl/api/spaces" -G --data-urlencode "partialName=$spaceName") 13 | space_id=$(echo "$spaces" | jq ".Items[] | select(.Name==\"${spaceName}\") | .Id" -r) 14 | 15 | # Get Tenant JSON 16 | tenant=$(curl -L -X GET -H "X-Octopus-ApiKey: $octopusApiKey" "$octopusUrl/api/$space_id/tenants?skip=0&take=1" -G --data-urlencode "partialName=$tenantName" -H "accept: application/json" | jq 'first(.Items[])' -r) 17 | 18 | # Get Tenant ID 19 | tenant_id=$(echo "${tenant}" | jq .Id -r) 20 | 21 | # Modify tag value 22 | tenant=$(echo "${tenant}" | sed -e "s/$oldTagValue/$newTagValue/g") 23 | 24 | # Put tenant 25 | curl -X PUT -H "X-Octopus-ApiKey: $octopusApiKey" -H "Content-Type: application/json" "$octopusUrl/api/$space_id/tenants/$tenant_id" -d "$tenant" -------------------------------------------------------------------------------- /REST/bash/Users/inviteInstanceUser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Bash script to programatically invite a new instance user via Octopus.com 4 | 5 | # LICENSE_KEY, OCTOPUS_ORG, COOKIE, and RV_TOKEN variables can be acquired by inspecting a user invite web request from Octopus.com and copying as a curl request. 6 | # OCTOPUS_TEAM variable can be set to any existing Octopus team. 7 | 8 | LICENSE_KEY="licensekeys-xxx" 9 | OCTOPUS_TEAM="Everyone" 10 | OCTOPUS_ORG="Organizations-xxx" 11 | COOKIE="" 12 | RV_TOKEN="" 13 | NEW_USER_EMAIL="user%40domain.com" 14 | NEW_USER_FULLNAME="" 15 | SEND_INVITE="true" 16 | 17 | curl "https://octopus.com/invitation" \ 18 | -H "content-type: application/x-www-form-urlencoded" \ 19 | -H "cookie: $COOKIE" \ 20 | --data-raw "OrganizationId=$OCTOPUS_ORG&LicenseId=$LICENSE_KEY&Email=$NEW_USER_EMAIL&FullName=$NEW_USER_FULLNAME&TargetSystemTeam=$OCTOPUS_TEAM&SendInvite=$SEND_INVITE&__RequestVerificationToken=$RV_TOKEN" 21 | -------------------------------------------------------------------------------- /REST/bash/Users/inviteOrgUser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Bash script to programatically invite a new organization user via Octopus.com 4 | 5 | # OCTOPUS_ORG, COOKIE, and RV_TOKEN variables can be acquired by inspecting a user invite web request from Octopus.com and copying as a curl request. 6 | # User roles: 0 = Billing, 1 = Tech, 2 = Administrator 7 | 8 | OCTOPUS_ORG="Organizations-xxx" 9 | COOKIE="" 10 | RV_TOKEN="" 11 | NEW_USER_EMAIL="user%40domain.com" 12 | NEW_USER_ROLE="0" 13 | 14 | curl "https://octopus.com/invitation/$OCTOPUS_ORG/invite" \ 15 | -H 'content-type: application/x-www-form-urlencoded' \ 16 | -H "cookie: $COOKIE" \ 17 | --data-raw "EmailAddress=$NEW_USER_EMAIL&role=$NEW_USER_ROLE&__RequestVerificationToken=$RV_TOKEN" 18 | -------------------------------------------------------------------------------- /REST/python/Deployments/cancel-queued-deployments.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | 9 | def get_octopus_resource(uri): 10 | response = requests.get(uri, headers=headers) 11 | response.raise_for_status() 12 | 13 | return json.loads(response.content.decode('utf-8')) 14 | 15 | 16 | def get_by_name(uri, name): 17 | resources = get_octopus_resource(uri) 18 | return next((x for x in resources if x['Name'] == name), None) 19 | 20 | 21 | space_name = 'Default' 22 | 23 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 24 | tasks = get_octopus_resource('{0}/{1}/tasks'.format(octopus_server_uri, space['Id'])) 25 | queued = [task for task in tasks['Items'] if task['State'] == 'Queued' and task['Name'] == 'Deploy' and not task['HasBeenPickedUpByProcessor']] 26 | 27 | for task in queued: 28 | uri = '{0}/{1}/tasks/{2}/cancel'.format(octopus_server_uri, space['Id'], task['Id']) 29 | response = requests.post(uri, headers=headers) 30 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Feeds/change-feed.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | space_name = "Default" 9 | feed_name = 'nuget.org' 10 | new_name = 'nuget.org updated feed' 11 | 12 | uri = '{0}/spaces/all'.format(octopus_server_uri) 13 | response = requests.get(uri, headers=headers) 14 | response.raise_for_status() 15 | 16 | spaces = json.loads(response.content.decode('utf-8')) 17 | space = next((x for x in spaces if x['Name'] == space_name), None) 18 | 19 | uri = '{0}/{1}/feeds/all'.format(octopus_server_uri, space['Id']) 20 | response = requests.get(uri, headers=headers) 21 | response.raise_for_status() 22 | 23 | feeds = json.loads(response.content.decode('utf-8')) 24 | feed = next((x for x in feeds if x['Name'] == feed_name), None) 25 | feed['Name'] = new_name 26 | 27 | uri = '{0}/{1}/feeds/{2}'.format(octopus_server_uri, space['Id'], feed['Id']) 28 | response = requests.put(uri, headers=headers, json=feed) 29 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Feeds/create-feed.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | space_name = 'Default' 9 | 10 | feed = { 11 | 'Id': None, 12 | 'Name': 'nuget.org', 13 | 'FeedUri': 'https://api.nuget.org/v3/index.json', 14 | 'FeedType': 'NuGet', 15 | 'DownloadAttempts': 5, 16 | 'DownloadRetryBackoffSeconds': 10, 17 | 'EnhancedMode': False 18 | # 'Username': 'uncomment to provide credentials' 19 | # 'Password': 'uncomment to provide credentials' 20 | } 21 | 22 | uri = '{0}/spaces/all'.format(octopus_server_uri) 23 | response = requests.get(uri, headers=headers) 24 | response.raise_for_status() 25 | 26 | spaces = json.loads(response.content.decode('utf-8')) 27 | space = next((x for x in spaces if x['Name'] == space_name), None) 28 | 29 | uri = '{0}/{1}/feeds'.format(octopus_server_uri, space['Id']) 30 | response = requests.post(uri, headers=headers, json=feed) 31 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Feeds/delete-feed.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | space_name = "Default" 9 | feed_name = "nuget.org" 10 | 11 | uri = '{0}/spaces/all'.format(octopus_server_uri) 12 | response = requests.get(uri, headers=headers) 13 | response.raise_for_status() 14 | 15 | spaces = json.loads(response.content.decode('utf-8')) 16 | space = next((x for x in spaces if x['Name'] == space_name), None) 17 | 18 | uri = '{0}/{1}/feeds/all'.format(octopus_server_uri, space['Id']) 19 | response = requests.get(uri, headers=headers) 20 | response.raise_for_status() 21 | 22 | feeds = json.loads(response.content.decode('utf-8')) 23 | feed = next((x for x in feeds if x['Name'] == feed_name), None) 24 | 25 | uri = '{0}/{1}/feeds/{2}'.format(octopus_server_uri, space['Id'], feed['Id']) 26 | response = requests.delete(uri, headers=headers) 27 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Feeds/download-package.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | space_name = "Default" 19 | package_output_folder = '/path/to/output/package/to' 20 | package_name = 'packagename' 21 | package_version = '1.0.0.0' 22 | 23 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 24 | package = get_octopus_resource('{0}/{1}/packages/packages-{2}.{3}'.format(octopus_server_uri, space['Id'], package_name, package_version)) 25 | 26 | uri = '{0}/{1}/packages/packages-{2}.{3}/raw'.format(octopus_server_uri, space['Id'], package_name, package_version) 27 | response = requests.get(uri, headers=headers) 28 | response.raise_for_status() 29 | package_output_file_path = '{0}/{1}.{2}{3}'.format(package_output_folder, package_name, package_version, package['FileExtension']) 30 | f = open(package_output_file_path, "wb") 31 | f.write(response.content) 32 | f.close() 33 | print('Downloaded package to \'{0}\''.format(package_output_file_path)) -------------------------------------------------------------------------------- /REST/python/Feeds/get-feeds.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | space_name = 'Default' 9 | 10 | uri = '{0}/spaces/all'.format(octopus_server_uri) 11 | response = requests.get(uri, headers=headers) 12 | response.raise_for_status() 13 | 14 | spaces = json.loads(response.content.decode('utf-8')) 15 | space = next((x for x in spaces if x['Name'] == space_name), None) 16 | 17 | uri = '{0}/{1}/feeds/all'.format(octopus_server_uri, space['Id']) 18 | response = requests.get(uri, headers=headers) 19 | response.raise_for_status() 20 | 21 | feeds = json.loads(response.content.decode('utf-8')) 22 | 23 | for feed in feeds: 24 | uri = feed.get('FeedUri', feed['FeedType']) 25 | print('{0} - {1} - {2}'.format(feed['Id'], feed['Name'], uri)) -------------------------------------------------------------------------------- /REST/python/Feeds/push-package.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | space_name = "Default" 9 | package_folder = '/folder/containing/package/' 10 | package_name = 'Package.Name.1.2.3.zip' 11 | 12 | uri = '{0}/spaces/all'.format(octopus_server_uri) 13 | response = requests.get(uri, headers=headers) 14 | response.raise_for_status() 15 | 16 | spaces = json.loads(response.content.decode('utf-8')) 17 | space = next((x for x in spaces if x['Name'] == space_name), None) 18 | 19 | with open('{0}{1}'.format(package_folder, package_name), 'rb') as package: 20 | uri = '{0}/{1}/packages/raw?replace=false'.format(octopus_server_uri, space['Id']) 21 | files = { 22 | 'fileData': (package_name, package, 'multipart/form-data', {'Content-Disposition': 'form-data'}) 23 | } 24 | 25 | response = requests.post(uri, headers=headers, files=files) 26 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Projects/delete-project-by-name.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | space_name = 'Default' 19 | project_name = 'Your Project Name' 20 | 21 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 22 | project = get_by_name('{0}/{1}/projects/all'.format(octopus_server_uri, space['Id']), project_name) 23 | 24 | uri = '{0}/{1}/projects/{2}'.format(octopus_server_uri, space['Id'], project['Id']) 25 | response = requests.delete(uri, headers=headers) 26 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Projects/delete-projects-without-processes.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | space_name = 'Default' 19 | 20 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 21 | projects = get_octopus_resource('{0}/{1}/projects/all'.format(octopus_server_uri, space['Id'])) 22 | 23 | for project in projects: 24 | process = get_octopus_resource('{0}/{1}/deploymentprocesses/{2}'.format(octopus_server_uri, space['Id'], project['DeploymentProcessId'])) 25 | steps = process.get('Steps', None) 26 | if steps is None or len(steps) == 0: 27 | print('Deleting project \'{0}\' as it has no deployment process'.format(project['Name'])) 28 | uri = '{0}/{1}/projects/{2}'.format(octopus_server_uri, space['Id'], project['Id']) 29 | response = requests.delete(uri, headers=headers) 30 | response.raise_for_status() 31 | -------------------------------------------------------------------------------- /REST/python/Projects/disable-project-triggers.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | space_name = 'Default' 19 | project_name = 'Your project' 20 | 21 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 22 | project = get_by_name('{0}/{1}/projects/all'.format(octopus_server_uri, space['Id']), project_name) 23 | project_triggers = get_octopus_resource('{0}/{1}/projects/{2}/triggers'.format(octopus_server_uri, space['Id'], project['Id'])) 24 | 25 | for trigger in project_triggers['Items']: 26 | print('Disabling project trigger {0} ({1})'.format(trigger['Name'], trigger['Id'])) 27 | trigger['IsDisabled'] = True 28 | uri = '{0}/{1}/projecttriggers/{2}'.format(octopus_server_uri, space['Id'], trigger['Id']) 29 | response = requests.put(uri, headers=headers, json=trigger) 30 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Projects/find-projects-using-variable-set.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | space_name = 'Default' 19 | libraryset_name = 'Your variable set name' 20 | 21 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 22 | library_variable_set = get_by_name('{0}/{1}/libraryvariablesets/all'.format(octopus_server_uri, space['Id']), libraryset_name) 23 | library_variable_set_id = library_variable_set['Id'] 24 | 25 | projects = get_octopus_resource('{0}/{1}/projects/all'.format(octopus_server_uri, space['Id'])) 26 | 27 | for project in projects: 28 | project_variable_sets = project['IncludedLibraryVariableSetIds'] 29 | if library_variable_set_id in project_variable_sets: 30 | print('Project \'{0}\' is using library variable set \'{1}\''.format(project['Name'], libraryset_name)) -------------------------------------------------------------------------------- /REST/python/Runbooks/create-runbook.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | space_name = 'Default' 19 | project_name = 'Your Project Name' 20 | runbook_name = 'Your new runbook name' 21 | 22 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 23 | project = get_by_name('{0}/{1}/projects/all'.format(octopus_server_uri, space['Id']), project_name) 24 | 25 | runbook = { 26 | 'Id': None, 27 | 'Name': runbook_name, 28 | 'ProjectId': project['Id'], 29 | 'EnvironmentScope': 'All', 30 | 'RunRetentionPolicy': { 31 | 'QuantityToKeep': 100, 32 | 'ShouldKeepForever': False 33 | } 34 | } 35 | 36 | uri = '{0}/{1}/runbooks'.format(octopus_server_uri, space['Id']) 37 | response = requests.post(uri, headers=headers, json=runbook) 38 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Spaces/delete-space.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | space_name = "Your Space name" 9 | 10 | def get_octopus_resource(uri): 11 | response = requests.get(uri, headers=headers) 12 | response.raise_for_status() 13 | 14 | return json.loads(response.content.decode('utf-8')) 15 | 16 | def get_by_name(uri, name): 17 | resources = get_octopus_resource(uri) 18 | return next((x for x in resources if x['Name'] == name), None) 19 | 20 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 21 | space['TaskQueueStopped'] = True 22 | 23 | # update task queue to stopped 24 | uri = '{0}/spaces/{1}'.format(octopus_server_uri, space['Id']) 25 | response = requests.put(uri, headers=headers, json=space) 26 | response.raise_for_status() 27 | 28 | # Delete space 29 | response = requests.delete(uri, headers=headers) 30 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Targets/add-role-to-target.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | 9 | def get_octopus_resource(uri): 10 | response = requests.get(uri, headers=headers) 11 | response.raise_for_status() 12 | 13 | return json.loads(response.content.decode('utf-8')) 14 | 15 | 16 | def get_by_name(uri, name): 17 | resources = get_octopus_resource(uri) 18 | return next((x for x in resources if x['Name'] == name), None) 19 | 20 | 21 | space_name = 'Default' 22 | target_name = 'Your Target Name' 23 | target_role = 'your-product-role' 24 | 25 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 26 | target = get_by_name('{0}/{1}/machines/all'.format(octopus_server_uri, space['Id']), target_name) 27 | 28 | target['Roles'].append(target_role) 29 | 30 | uri = '{0}/{1}/machines/{2}'.format(octopus_server_uri, space['Id'], target['Id']) 31 | response = requests.put(uri, headers=headers, json=target) 32 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Targets/change-target-machine-policy.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | 9 | def get_octopus_resource(uri): 10 | response = requests.get(uri, headers=headers) 11 | response.raise_for_status() 12 | 13 | return json.loads(response.content.decode('utf-8')) 14 | 15 | 16 | def get_by_name(uri, name): 17 | resources = get_octopus_resource(uri) 18 | return next((x for x in resources if x['Name'] == name), None) 19 | 20 | 21 | space_name = 'Default' 22 | target_name = 'Your Target Name' 23 | machine_policy_name = 'Your Machine Policy Name' 24 | 25 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 26 | target = get_by_name('{0}/{1}/machines/all'.format(octopus_server_uri, space['Id']), target_name) 27 | machine_policy = get_by_name('{0}/{1}/machinepolicies/all'.format(octopus_server_uri, space['Id']), machine_policy_name) 28 | 29 | target['MachinePolicyId'] = machine_policy['Id'] 30 | uri = '{0}/{1}/machines/{2}'.format(octopus_server_uri, space['Id'], target['Id']) 31 | response = requests.put(uri, headers=headers, json=target) 32 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Targets/delete-target-by-name.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | 9 | def get_octopus_resource(uri): 10 | response = requests.get(uri, headers=headers) 11 | response.raise_for_status() 12 | 13 | return json.loads(response.content.decode('utf-8')) 14 | 15 | 16 | def get_by_name(uri, name): 17 | resources = get_octopus_resource(uri) 18 | return next((x for x in resources if x['Name'] == name), None) 19 | 20 | 21 | space_name = 'Default' 22 | target_name = 'Your Target Name' 23 | 24 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 25 | target = get_by_name('{0}/{1}/machines/all'.format(octopus_server_uri, space['Id']), target_name) 26 | 27 | uri = '{0}/{1}/machines/{2}'.format(octopus_server_uri, space['Id'], target['Id']) 28 | response = requests.delete(uri, headers=headers) 29 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Targets/delete-targets-by-role.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | def get_by_role(uri, role): 19 | resources = get_octopus_resource(uri) 20 | return (r for r in resources if role in r['Roles']) 21 | 22 | space_name = 'Default' 23 | target_role = 'your-target-role' 24 | 25 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 26 | targets = get_by_role('{0}/{1}/machines/all'.format(octopus_server_uri, space['Id']), target_role) 27 | 28 | for target in targets: 29 | print('Deleting {0} ({1})'.format(target['Name'], target['Id'])) 30 | uri = '{0}/{1}/machines/{2}'.format(octopus_server_uri, space['Id'], target['Id']) 31 | response = requests.delete(uri, headers=headers) 32 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Targets/enable-or-disable-target.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | 9 | def get_octopus_resource(uri): 10 | response = requests.get(uri, headers=headers) 11 | response.raise_for_status() 12 | 13 | return json.loads(response.content.decode('utf-8')) 14 | 15 | 16 | def get_by_name(uri, name): 17 | resources = get_octopus_resource(uri) 18 | return next((x for x in resources if x['Name'] == name), None) 19 | 20 | 21 | space_name = 'Default' 22 | target_name = 'Your Target Name' 23 | disable_target = False 24 | 25 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 26 | target = get_by_name('{0}/{1}/machines/all'.format(octopus_server_uri, space['Id']), target_name) 27 | 28 | target['IsDisabled'] = disable_target 29 | 30 | uri = '{0}/{1}/machines/{2}'.format(octopus_server_uri, space['Id'], target['Id']) 31 | response = requests.put(uri, headers=headers, json=target) 32 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/python/Targets/upgrade-targets.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | octopus_server_uri = 'https://your.octopus.app/api' 5 | octopus_api_key = 'API-YOURAPIKEY' 6 | headers = {'X-Octopus-ApiKey': octopus_api_key} 7 | 8 | def get_octopus_resource(uri): 9 | response = requests.get(uri, headers=headers) 10 | response.raise_for_status() 11 | 12 | return json.loads(response.content.decode('utf-8')) 13 | 14 | def get_by_name(uri, name): 15 | resources = get_octopus_resource(uri) 16 | return next((x for x in resources if x['Name'] == name), None) 17 | 18 | 19 | space_name = 'Default' 20 | target_names = ['Target A', 'Target B'] 21 | 22 | space = get_by_name('{0}/spaces/all'.format(octopus_server_uri), space_name) 23 | targets = get_octopus_resource('{0}/{1}/machines/all'.format(octopus_server_uri, space['Id'])) 24 | target_ids = [target['Id'] for target in targets if target['Name'] in target_names] 25 | 26 | task = { 27 | 'Name': 'Upgrade', 28 | 'Arguments': { 29 | 'MachineIds': target_ids 30 | }, 31 | 'Description': 'Upgrade machines', 32 | 'SpaceId': space['Id'] 33 | } 34 | 35 | uri = '{0}/{1}/tasks'.format(octopus_server_uri, 36 | space['Id']) 37 | response = requests.post(uri, headers=headers, json=task) 38 | response.raise_for_status() -------------------------------------------------------------------------------- /REST/ruby/Deployments/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rest-client' 3 | gem 'json' 4 | --------------------------------------------------------------------------------