Release cannot be deployed to environment

We are getting the following issue on on certain environments not all but cant figure out what might be the difference between a working environment and the non working one.

=================================================================================================
Octopus Deploy Command Line Tool, version 2.5.10.39
Handshaking with Octopus server:
Info 08:46:57
Handshake successful. Octopus version: 2.6.0.751; API version: 3.0.0
Finding project: Web.Framework.UI.Views
Finding latest release for project
Release ‘16.49.548’ of project ‘Web.Framework.UI.Views’ cannot be deployed to environment ‘LM110’ because the environment is not in the list of environments that this release can be deployed to. This may be because a) the environment does not exist, b) the name is misspelled, c) you don’t have permission to deploy to this environment, or d) the environment is not in the list of environments defined by the project group.
Exit code: -1
f:\utils\OD\Octo.exe deploy-release --project=Web.Framework.UI.Views --version=latest -waitfordeployment=true --deployto=LM110 --server=http://odserver --apikey=API-DDUQECCCTWZHKSDW3BFHDQCDC9K
Info 08:46:57

PowerShell exit code: -1

Thanks,

to add to the above

Project group has a correct assignment and also the each process has the right environment assign to them.

Hi Sam,

Thanks for getting in touch! There are a few things that can cause this error so I have some things for you to check.

The first thing I notice is you are using version 2.6.0.751 of Octopus yet your API version is 3.0.0. These are incompatible. Based off your logs I am assuming you are running in TeamCity. You need to select version 2.0 of Octopus in the Octopus deploy-release step settings in TeamCity.
The second is that it is case sensitive. Can you check that you have the spelling and cases correct for your environment. Also check for spaces as that can cause this problem.
The third thing to check is can this release be deployed to this environment or is it not in the correct phase of your Lifecycle.
Fourth, check that the API key has permissions to deploy to that environment.

If you could check all the above for me hopefully it will resolve your issue.

Vanessa

Hi Venessa,

sorry for the late reply. Currently we use a powershell to call OD from team city and we are not specifying any version of the API. here is the part we have in the script.

OCTOPUS SERVER SETTINGS

$octoServer=“http://DevODServer01
$apiKey=“API-KEY”
$Auth= @{“Authorization”=“Basic $($EncodedPassword)”;“X-Octopus-APiKey”=“API-KEY”} # THIS IS API HEADER USED WHEN MAKING RESTAPI CALLS

can i add a parameter to specify in there?

Thank you in advance.

Also another observation, if i deploy the package the project by it self it works fine, but that project step fails if i run it by using the orchestrator.

Hi Sam,

Vanessa’s hands were a bit full and I decided to tag along in this ticket to give her a hand, as I’m slightly more familiar with our API usage :slight_smile:

One thing I don’t fully understand about your scenario is this:

In the error message of your first reply I can clearly see that you are using Octo.exe to create the release, and that is giving you an error about being unable to deploy the release to a certain environment. Vanessa’s comments are spot on to start troubleshooting that part alone.

Then on your second reply you mention you are using Powershell to call OD from TeamCity, and not Octo.exe. Is that correct? If that is the case, then:

  • For what are you using Octo.exe during your build exactly?
  • For what other action are you using Powershell to make raw api calls? It’ll be cool if you could send the full code snippet you are using here in a gist.
  • Could you send us a full build log also?

Couple of things to mention about your last reply with the PS code:

  • In the line $Auth= @{"Authorization"="Basic $($EncodedPassword)";"X-Octopus-APiKey"="API-KEY"} # THIS IS API HEADER USED WHEN MAKING RESTAPI CALLS you don’t really need to add the Autorization field to the header. Just X-Octopus-APIKey is enough.

  • You cannot say to which version of the API you want to hit from the API call itself. You’ll always be using whichever version the Octopus server is running. So your code needs to tailor to that version.

Best regards,
Dalmiro