PowerShell automation scripts for Octopus Deploy release management and deployment orchestration.
This repository contains PowerShell scripts designed to streamline and automate deployment processes using Octopus Deploy. These scripts handle various aspects of the release pipeline, from build preparation to deployment execution and post-deployment verification.
- PowerShell: Version 5.1 or higher (PowerShell 7+ recommended)
- Octopus Deploy: Server version 2020.1 or higher
- Octopus CLI: Install the Octopus Deploy CLI tools
- API Key: Valid Octopus Deploy API key with appropriate permissions
Ensure your Octopus Deploy API key has the following permissions:
- Project viewer/deployer rights
- Environment deployment permissions
- Release creation capabilities
-
Clone this repository:
git clone <repository-url> cd devops-release-scripts
-
Install Octopus CLI (if not already installed):
choco install octopustools # or dotnet tool install Octopus.DotNet.Cli --global
-
Configure your Octopus Deploy connection:
$env:OCTOPUS_URL = "https://your-octopus-server.com" $env:OCTOPUS_API_KEY = "API-XXXXXXXXXXXXXXXXXXXXXXXXXX"
.
βββ scripts/
β βββ deployment/ # Deployment execution scripts
β βββ releases/ # Release creation and management
β βββ utilities/ # Helper functions and utilities
β βββ rollback/ # Rollback and recovery scripts
βββ config/
β βββ environments.json # Environment configuration
βββ tests/
β βββ *.Tests.ps1 # Pester test files
βββ README.md
.\scripts\releases\Create-Release.ps1 `
-ProjectName "MyProject" `
-Version "1.0.0" `
-ReleaseNotes "Release notes here".\scripts\deployment\Deploy-Release.ps1 `
-ProjectName "MyProject" `
-Environment "Production" `
-ReleaseVersion "1.0.0".\scripts\deployment\Promote-Release.ps1 `
-ProjectName "MyProject" `
-FromEnvironment "Staging" `
-ToEnvironment "Production"Creates a new release in Octopus Deploy with specified package versions and release notes.
Parameters:
ProjectName- Name of the Octopus projectVersion- Release version numberReleaseNotes- Optional release notesPackageVersion- Specific package version to use
Deploys a specific release to a target environment.
Parameters:
ProjectName- Name of the Octopus projectEnvironment- Target environment nameReleaseVersion- Version of release to deployWaitForCompletion- Wait for deployment to complete (default: true)
Rolls back to a previous deployment version.
Parameters:
ProjectName- Name of the Octopus projectEnvironment- Environment to rollbackTargetVersion- Version to rollback to
Set the following environment variables for authentication:
$env:OCTOPUS_URL = "https://octopus.company.com"
$env:OCTOPUS_API_KEY = "API-YOURAPIKEY"
$env:OCTOPUS_SPACE = "Default" # Optional, if using spacesEdit config/environments.json to customize environment-specific settings:
{
"environments": [
{
"name": "Production",
"requiresApproval": true,
"notificationEmail": "team@company.com"
},
{
"name": "Staging",
"requiresApproval": false
}
]
}- Always test in lower environments first - Deploy to Dev/Test before Production
- Use semantic versioning - Follow SemVer for release versions
- Include meaningful release notes - Document changes in each release
- Enable logging - Use the
-Verboseflag for detailed output - Validate before deployment - Run pre-deployment checks
- Monitor deployments - Watch deployment progress and logs
Run Pester tests to validate scripts:
Invoke-Pester -Path .\tests\π Authentication Errors
- Verify your API key is valid and has necessary permissions
- Check that OCTOPUS_URL is correctly set
β±οΈ Connection Timeouts
- Ensure network connectivity to Octopus server
- Verify firewall rules allow HTTPS traffic
β Deployment Failures
- Check Octopus Deploy logs for detailed error messages
- Verify target machines are online and accessible
- Ensure deployment steps are properly configured
- Create a feature branch from
main - Make your changes and test thoroughly
- Update documentation as needed
- Submit a pull request with a clear description
- Never commit API keys or secrets - Use environment variables
- Store sensitive configuration in Azure Key Vault or similar
- Rotate API keys regularly
- Use least-privilege access principles
For issues or questions:
- Check Octopus Deploy documentation: https://octopus.com/docs
- Review script comments and help documentation
- Contact the DevOps team
[Specify your license here]
[Your team/organization name]
Last Updated: November 2025