Is it possible, using octo.exe to, for instance: get/list all projects with latest successfully deployed releases into a specific environment (example: Development)?
Here is some code that I am trying to set it up:
# Get list of all projects | trip unecessary strings | write into txt file nice list of all projects
$projects = .\Octo.exe list-projects --APIkey $octopusAPIKey --server $octopusURL | Select-
Object -Skip 6
$all = $projects.Substring(3) -replace "\(ID.*\)",'' | Out-File projects.txt
# Deploy latest releases to the all DEV environments
.\Octo.exe deploy-release --version latest --deployto "DEV" --APIkey $env:octopusAPIKey --server
$env:octopusURL --project $all
How to make this to work? As I do not know how to pass all projects to –project and if it is possible to do it on this way?
Regarding your script, Octo.exe deploy-release works for one project at a time. You could iterate through your projects using Octo.exe deploy-release for each project. For example:
Thank you for your prompt answer, it seems your advice have a positive results. But, is it possible to add Target role, so deploy-release can redeploy only, for instance on Web servers?
Example:
we add a new web server called WEB5 and want to redeploy to WEB5 all latest deployed releases which are deployed only to “Development” environment, and have target role “Webservers” where are all WEB1-4 servers. As WEB1-4 will be deleted at one moment, this is practically migration.
Your previous post works for us, but it will redeploy latest deployments which are marked as “Development” to all target roles. And we want only to redeploy “Development” to target role “Webservers” where we include a new WEB5. In that case, we’ll have consistent environments to all web servers and then we can power off one old node (WEB1-4 servers). Trigger part won;t work as it will take a lot of time to setup trigger to each project.
Hope this is make sense, let me know if need to clarify a bit.
You can create a deployment to a specific machine via the API if you know the ID of the machine. This is not supported using Octo.exe so you would need to write some custom API script to do it. I can help if you’d like.
It sounds like you could use automatic deployment triggers that will deploy to the WebServers role in the Development environment. You could create the triggers programmatically on all of the projects with an API script, I can also help with that if you want.
If it is possible to create the trigger to all projects from one shot, then this might be useful. I didn;'t work with API in the past, this is all new to me.
How to trigger deployments to a new node with WebServer role in the Deployment environment?
Here is an example PowerShell script you could use to create project triggers for all of your projects:
The script is idempotent as long as the script name remains the same, so you can re-run this script when you add new projects or change the action and filter options and will not create duplicate triggers.
It seems it won’t put the right trigger role in the trigger. Whit this code, it creates the trigger, where environment is DEV and target roles are DEV. variable $triggerRole = "Web-server only applies in the name of the trigger. And we need target role to be Web-server.
Perfect, I’ll test today. Thank you so much!
One more question, how to delete all these new created triggers? As there is a lot project which won’t goes to this target roles, etc…
This line doesn’t work on my side. IS there a way to pass some argument and value, like delete all triggers with name “Automatically deploy to Web-Server”?
If you use PowerShell ISE there should be intellisense to help you figure out which methods are available, or if you prefer Octopus.Client also work with C#.
Exception calling "FindByName" with "1" argument(s): "Unable to process response from server:
Requested value 'DailySchedule' was not found.. Response co
ntent: {
"ItemType": "ProjectTrigger",
"TotalResults": 10,
"ItemsPerPage": 30,
"NumberOfPages":"
At C:\Users\adm-bradjur\Desktop\DeleteTriggers.ps1:11 char:1
+ $triggers = $repository.ProjectTriggers.FindByName("Automatically dep ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : OctopusDeserializationException
Thank you for your help!
I’ll try to figure this out and let you know for the outcome.
PS. Not sure why this error occurs, but after rebooting the server, script is working, except it only delete trigger from one project (one trigger). Each time I execute script, it delete one trigger by one.