-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update CreateProject.ps1 #147
Open
donnybell
wants to merge
20
commits into
master
Choose a base branch
from
donnybell-patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a7c082a
Update CreateProject.ps1
donnybell d9059fb
Update CreateProject.ps1
donnybell 4738e08
Update CreateProject.ps1
donnybell fad42d9
Update and rename DisableProject.ps1 to DisableOrEnableProject.ps1
donnybell 00f905d
Update DisableOrEnableProject.ps1
donnybell 6185fe7
Update CreateProject.ps1
donnybell 43d99f2
Update DeleteProjectByName.ps1
donnybell bdc772b
Update RenameProject.ps1
donnybell b6f449d
Update RenameProject.ps1
donnybell 725857a
Update RenameProject.ps1
donnybell de1bcab
Update RenameProject.ps1
donnybell 1ee8fc2
Update RenameProject.ps1
donnybell 5fd0cb7
Update RenameProject.ps1
donnybell b968a54
Update RenameProject.ps1
donnybell f2f3b5d
Update RenameProject.ps1
donnybell 3ceb760
Update and rename DeleteProjectsWithoutDeploymentProcess.ps1 to Listo…
donnybell 1e1f650
Update ListorDeleteProjectsWithoutDeploymentProcess.ps1
donnybell 6ad2251
Update RenameProject.ps1
donnybell dcb0d48
Update CreateProject.ps1
donnybell a3b2e28
Update CreateProject.ps1
donnybell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,82 @@ | ||
# ================================================================================================================== | ||
# This script creates a standard Project on the specified Octopus Server. | ||
# To make the new Project Git-enabled (config-as-code), navigate to the new Project URL > Settings > Version Control | ||
# ================================================================================================================== | ||
|
||
$ErrorActionPreference = "Stop"; | ||
|
||
# Define working variables | ||
$octopusURL = "https://youroctourl" | ||
$octopusAPIKey = "API-YOURAPIKEY" | ||
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } | ||
$spaceName = "default" | ||
$projectName = "MyProject" | ||
$projectDescription = "MyDescription" | ||
$projectGroupName = "Default project group" | ||
$lifecycleName = "Default lifecycle" | ||
# ====== BYPASS PROMPTS? ====== | ||
$BypassPrompts = $false # Set to $true if you wish to predefine your parameters | ||
|
||
|
||
# Get space | ||
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} | ||
# ====== PARAMETERS ====== | ||
If ($BypassPrompts) { | ||
|
||
# === Predefined Parameters (Optional) === | ||
$OctopusURL = "http://YOUR_OCTOPUS_URL.bla" | ||
$OctopusAPIKey = "API-XXXXXXXXXXXXXXXXXX" | ||
$SpaceId = "Spaces-XX" | ||
$ProjectName = "My Project" | ||
$ProjectDescription = "My Description" | ||
$ProjectGroupName = "Default Project Group" | ||
$LifecycleName = "Default Lifecycle" | ||
} | ||
|
||
# Get project group | ||
$projectGroup = (Invoke-RestMethod -Method Get "$octopusURL/api/$($space.Id)/projectgroups/all" -Headers $header) | Where-Object {$_.Name -eq $projectGroupName} | ||
If (!$BypassPrompts) { | ||
|
||
# === Prompted Parameters === | ||
$OctopusAPIKey = (Read-Host "Enter your Octopus API key (example: `"API-XXXXXXXXXXXXXXXXXX`")").trim('"') | ||
$OctopusURL = (Read-Host "Enter your Octopus Instance URL with no trailing slash (i.e. `"http://YOUR_OCTOPUS_URL.bla`")").trim('"') | ||
$SpaceId = (Read-Host "Enter the SpaceId where the Library Variable Set resides (example: `"Spaces-1`")").trim('"') | ||
$ProjectName = (Read-Host "Enter a name for your new Project (example: `"My Project`")").trim('"') | ||
$ProjectDescription = (Read-Host "Enter a description for your new Project (example: `"My Description`")").trim('"') | ||
$ProjectGroupName = (Read-Host "Enter the name of an existing Project Group in `"$($SpaceId)`" for your new Project (example: `"Default Project Group`")").trim('"') | ||
$LifecycleName = (Read-Host "Enter the name of an existing Lifecycle in `"$($SpaceId)`" for your new Project (example: `"Default Lifecycle`")").trim('"') | ||
} | ||
|
||
# Get Lifecycle | ||
$lifeCycle = (Invoke-RestMethod -Method Get "$octopusURL/api/$($space.Id)/lifecycles/all" -Headers $header) | Where-Object {$_.Name -eq $lifecycleName} | ||
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } | ||
|
||
# Create project json payload | ||
$jsonPayload = @{ | ||
Name = $projectName | ||
Description = $projectDescription | ||
ProjectGroupId = $projectGroup.Id | ||
LifeCycleId = $lifeCycle.Id | ||
|
||
# ====== SCRIPT BODY ====== | ||
# Try to GET the ProjectGroupId for $ProjectGroupName | ||
Try { | ||
$ProjectGroup = (Invoke-RestMethod -Method GET "$($OctopusURL)/api/$($SpaceId)/ProjectGroups/all" -Headers $Header) | Where-Object {$_.Name -eq $ProjectGroupName} | ||
If (!$ProjectGroup) {throw} | ||
} | ||
Catch { | ||
Write-Warning "Unable to find a ProjectGroupId for the Project Group Name `"$($ProjectGroupName)`" via `"$($OctopusURL)/api/$($SpaceId)/ProjectGroups/all`"" | ||
Write-Warning "Check your parameters (Octopus API key, URL, SpaceId, etc.), ensure your API key has sufficient permissions, and the Octopus Server is accessible from this machine." | ||
break | ||
} | ||
|
||
# Create project | ||
Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($space.Id)/projects" -Body ($jsonPayload | ConvertTo-Json -Depth 10) -Headers $header | ||
# Try to GET the LifecycleId for $LifecycleName | ||
Try { | ||
$Lifecycle = (Invoke-RestMethod -Method GET "$($OctopusURL)/api/$($SpaceId)/Lifecycles/all" -Headers $Header) | Where-Object {$_.Name -eq $LifecycleName} | ||
If (!$Lifecycle) {throw} | ||
} | ||
Catch { | ||
Write-Warning "Unable to find a LifecycleId for the Lifecycle Name `"$($LifecycleName)`" via `"$($OctopusURL)/api/$($SpaceId)/Lifecycles/all`"" | ||
Write-Warning "Check your parameters (Octopus API key, URL, SpaceId, etc.), ensure your API key has sufficient permissions, and the Octopus Server is accessible from this machine." | ||
break | ||
} | ||
|
||
# Create Json payload for new Project creation | ||
$JsonPayload = @{ | ||
Name = $ProjectName | ||
Description = $ProjectDescription | ||
ProjectGroupId = $ProjectGroup.Id | ||
LifecycleId = $Lifecycle.Id | ||
} | ||
|
||
# Create Project using $JsonPayload | ||
Try { | ||
$CheckProjName = (Invoke-RestMethod -Method GET -Uri "$($OctopusURL)/api/$($SpaceId)/projects/all" -Headers $Header) | Where-Object {$_.Name -eq $ProjectName} | ||
If ($CheckProjName) {throw} | ||
Else { | ||
$NewProject = Invoke-RestMethod -Method POST -Uri "$($OctopusURL)/api/$($SpaceId)/projects" -Body ($JsonPayload | ConvertTo-Json -Depth 10) -Headers $Header | ||
Write-Host "You may view your new Project at: $($OctopusURL)$($NewProject.Links.Self)" | ||
} | ||
} | ||
Catch { | ||
Write-Warning "A Project with the name `"$($ProjectName)`" already exists in `"$($SpaceId)`". Please choose a Project Name that does not exist in this Space." | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,70 @@ | ||
$ErrorActionPreference = "Stop"; | ||
# ================================================================================================================== | ||
# This script deletes a Project on the specified Octopus Server. | ||
# ================================================================================================================== | ||
|
||
# Define working variables | ||
$octopusURL = "https://youroctourl" | ||
$octopusAPIKey = "API-YOURAPIKEY" | ||
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } | ||
$spaceName = "Default" | ||
$projectName = "MyProject" | ||
$ErrorActionPreference = "Stop"; | ||
|
||
# Get space | ||
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName} | ||
# ====== BYPASS PROMPTS? ====== | ||
$BypassPrompts = $false # Set to $true if you wish to predefine your parameters | ||
|
||
# Get project | ||
$project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName} | ||
|
||
# Delete project | ||
Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/projects/$($project.Id)" -Headers $header | ||
# ====== PARAMETERS ====== | ||
If ($BypassPrompts) { | ||
|
||
# === Predefined Parameters (Optional) === | ||
$OctopusURL = "http://YOUR_OCTOPUS_URL.bla" | ||
$OctopusAPIKey = "API-XXXXXXXXXXXXXXXXXX" | ||
$SpaceId = "Spaces-XX" | ||
$ProjectName = "My Project" | ||
} | ||
|
||
If (!$BypassPrompts) { | ||
|
||
# === Prompted Parameters === | ||
$OctopusAPIKey = (Read-Host "Enter your Octopus API key (example: `"API-XXXXXXXXXXXXXXXXXX`")").trim('"') | ||
$OctopusURL = (Read-Host "Enter your Octopus Instance URL with no trailing slash (i.e. `"http://YOUR_OCTOPUS_URL.bla`")").trim('"') | ||
$SpaceId = (Read-Host "Enter the SpaceId where the Library Variable Set resides (example: `"Spaces-1`")").trim('"') | ||
$ProjectName = (Read-Host "Enter a name for your new Project (example: `"My Project`")").trim('"') | ||
} | ||
|
||
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } | ||
|
||
# ====== SCRIPT BODY ====== | ||
# Try to GET the ProjectId for $ProjectName | ||
Try { | ||
$Project = (Invoke-RestMethod -Method GET "$($OctopusURL)/api/$($SpaceId)/Projects/all" -Headers $Header) | Where-Object {$_.Name -eq $ProjectName} | ||
If (!$Project) {throw} | ||
} | ||
Catch { | ||
Write-Warning "Unable to find a ProjectId for the Project Name `"$($ProjectName)`" via `"$($OctopusURL)/api/$($SpaceId)/Projects/all`"" | ||
Write-Warning "Check your parameters (Octopus API key, URL, SpaceId, etc.), ensure your API key has sufficient permissions, and the Octopus Server is accessible from this machine." | ||
break | ||
} | ||
|
||
# Confirmation (ignored if $BypassPrompts = $true) | ||
If (!$BypassPrompts) { | ||
Write-Host "==================================================================================================================================" | ||
$Confirm = (Read-Host "Are you sure you want to DELETE the Project `"$ProjectName`" ($($Project.Id))? This cannot be undone. (Type Y to continue or N to quit)").trim('"') | ||
While (($Confirm -ne "N") -and ($Confirm -ne "Y")) { | ||
$Confirm = (Read-Host "Are you sure you want to DELETE the Project `"$ProjectName`" ($($Project.Id))? This cannot be undone. (Type Y to continue or N to quit)").trim('"') | ||
} | ||
If ($Confirm -eq "N") { | ||
Write-Warning "Aborted. No changes were made." | ||
break | ||
} | ||
} | ||
|
||
# Delete Project | ||
Invoke-RestMethod -Method DEL "$($OctopusURL)/api/$($SpaceId)/Projects/$($Project.Id)" -Headers $Header | ||
Try { | ||
$DeleteCheck = (Invoke-RestMethod -Method GET "$($OctopusURL)/api/$($SpaceId)/Projects/all" -Headers $Header) | Where-Object {$_.Name -eq $ProjectName} | ||
If (!$DeleteCheck) { | ||
Write-Host "The Project named `"$($ProjectName)`" ($($Project.Id)) was DELETED." | ||
} | ||
If ($DeleteCheck) {throw} | ||
} | ||
Catch { | ||
Write-Warning "Unable to DELETE the Project `"$($ProjectName)`" via `"$($OctopusURL)/api/$($SpaceId)/Projects/$($Project.Id)`"" | ||
Write-Warning "Check your parameters (Octopus API key, URL, SpaceId, etc.), ensure your API key has sufficient permissions, and the Octopus Server is accessible from this machine." | ||
break | ||
} |
26 changes: 0 additions & 26 deletions
26
REST/PowerShell/Projects/DeleteProjectsWithoutDeploymentProcess.ps1
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# ================================================================================================================== | ||
# This script disables or enables a Project on the specified Octopus Server. | ||
# ================================================================================================================== | ||
|
||
$ErrorActionPreference = "Stop"; | ||
|
||
# ====== BYPASS PROMPTS? ====== | ||
$BypassPrompts = $false # Set to $true if you wish to predefine your parameters | ||
|
||
|
||
# ====== PARAMETERS ====== | ||
If ($BypassPrompts) { | ||
|
||
# === Predefined Parameters (Optional) === | ||
$OctopusURL = "http://YOUR_OCTOPUS_URL.bla" | ||
$OctopusAPIKey = "API-XXXXXXXXXXXXXXXXXX" | ||
$SpaceId = "Spaces-XX" | ||
$ProjectName = "My Project" | ||
$ProjectEnabled = $false | ||
} | ||
|
||
If (!$BypassPrompts) { | ||
|
||
# === Prompted Parameters === | ||
$OctopusAPIKey = (Read-Host "Enter your Octopus API key (example: `"API-XXXXXXXXXXXXXXXXXX`")").trim('"') | ||
$OctopusURL = (Read-Host "Enter your Octopus Instance URL with no trailing slash (i.e. `"http://YOUR_OCTOPUS_URL.bla`")").trim('"') | ||
$SpaceId = (Read-Host "Enter the SpaceId where the Library Variable Set resides (example: `"Spaces-1`")").trim('"') | ||
$ProjectName = (Read-Host "Enter a name for your new Project (example: `"My Project`")").trim('"') | ||
$ProjectStatusPrompt = (Read-Host "Type `"D`" to Disable or `"E`" to Enable `"$($ProjectName)`"").trim('"') | ||
While (($ProjectStatusPrompt -ne "D") -and ($ProjectStatusPrompt -ne "E")) { | ||
$ProjectStatusPrompt = (Read-Host "Type `"D`" to Disable or `"E`" to Enable `"$($ProjectName)`"").trim('"') | ||
} | ||
If ($ProjectStatusPrompt -eq "D") {$ProjectEnabled = $false} | ||
If ($ProjectStatusPrompt -eq "E") {$ProjectEnabled = $true} | ||
} | ||
|
||
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } | ||
|
||
|
||
# ====== SCRIPT BODY ====== | ||
# Try to GET the ProjectId for $ProjectName | ||
Try { | ||
$Project = (Invoke-RestMethod -Method GET "$($OctopusURL)/api/$($SpaceId)/Projects/all" -Headers $Header) | Where-Object {$_.Name -eq $ProjectName} | ||
If (!$Project) {throw} | ||
} | ||
Catch { | ||
Write-Warning "Unable to find a ProjectId for the Project Name `"$($ProjectName)`" via `"$($OctopusURL)/api/$($SpaceId)/Projects/all`"" | ||
Write-Warning "Check your parameters (Octopus API key, URL, SpaceId, etc.), ensure your API key has sufficient permissions, and the Octopus Server is accessible from this machine." | ||
break | ||
} | ||
|
||
# Check if Project is already Disabled/Enabled | ||
If ($Project.IsDisabled -eq !$ProjectEnabled) { | ||
If ($Project.IsDisabled) { | ||
Write-Host "`"$($ProjectName)`" ($($Project.Id)) already disabled! No action required!" | ||
break | ||
} | ||
If (!$Project.IsDisabled) { | ||
Write-Host "`"$($ProjectName)`" ($($Project.Id)) already enabled! No action required!" | ||
break | ||
} | ||
} | ||
|
||
# Disable/Enable Project | ||
$Project.IsDisabled = !$ProjectEnabled | ||
If ($ProjectEnabled -eq $false) { | ||
Write-Host "Disabling `"$($ProjectName)`" ($($Project.Id))" | ||
} | ||
If ($ProjectEnabled -eq $true) { | ||
Write-Host "Enabling `"$($ProjectName)`" ($($Project.Id))" | ||
} | ||
# Save Project changes | ||
Try { | ||
$SaveProject = Invoke-RestMethod -Method PUT -Uri "$($OctopusURL)/api/$($SpaceId)/Projects/$($Project.Id)" -Headers $Header -Body ($Project | ConvertTo-Json -Depth 10) | ||
} | ||
Catch { | ||
Write-Warning "Something went wrong when attempting a PUT via `"$($OctopusURL)/api/$($SpaceId)/Projects/$($Project.Id)`"." | ||
} | ||
|
||
$ProjectCheck = Invoke-RestMethod -Method GET -Uri "$($OctopusURL)/api/$($SpaceId)/Projects/$($Project.Id)" -Headers $Header | ||
If ($ProjectCheck.IsDisabled -eq !$ProjectEnabled) { | ||
Write-Host "Success!" | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Including more detailed exceptions for other possibilities could be a good improvement, to save someone scratching their head at why a server error returned a message saying a project already exists.