Deployment happening on all Tenants, even though it should be for only one

I have a really weird situation going on. I am running the following powershell command to create a deployment:

Invoke-WebRequest -Uri http://octoserver/api/Spaces-2/deployments -Method POST -Headers @{"X-Octopus-ApiKey"="API-REDACTED"} -Body "{'EnvironmentId':'Environments-101','TenantId':'Tenants-61','ReleaseId':'Releases-32965'}" -ErrorVariable octoError

This is set to deploy to ONLY Tenants-61, but it ends up deploying to ALL the tenants in that project (bad).

Here is a screen shot:

I look at the results of the above Invoke-WebRequest call and it looks like this:

Deploy Results Json
 {
  "Id": "Deployments-51167",
  "SpaceId": "Spaces-2",
  "ReleaseId": "Releases-32966",
  "ChannelId": "Channels-1481",
  "DeploymentProcessId": "deploymentprocess-Projects-1201-s-0-S3EQL",
  "Changes": [
    {
      "Version": "1.0.0.26",
      "ReleaseNotes": null,
      "BuildInformation": [],
      "WorkItems": [],
      "Commits": []
    }
  ],
  "ChangesMarkdown": "\r\n**Release 1.0.0.26**\r\n\r\n\r\n\r\n",
  "EnvironmentId": "Environments-101",
  "TenantId": "Tenants-61",
  "ForcePackageDownload": false,
  "ForcePackageRedeployment": false,
  "SkipActions": [],
  "SpecificMachineIds": [],
  "ExcludedMachineIds": [],
  "ManifestVariableSetId": "variableset-Deployments-51167",
  "TaskId": "ServerTasks-151426",
  "ProjectId": "Projects-1201",
  "UseGuidedFailure": false,
  "Comments": null,
  "FormValues": {},
  "QueueTime": null,
  "QueueTimeExpiry": null,
  "Name": "Deploy to DevUnstable for Blue (#2)",
  "Created": "2021-12-17T02:30:44.635+00:00",
  "TentacleRetentionPeriod": {
    "Unit": "Days",
    "QuantityToKeep": 0,
    "ShouldKeepForever": true
  },
  "DeployedBy": "myuser@mydomain.com",
  "DeployedById": "Users-922",
  "FailureEncountered": false,
  "DeployedToMachineIds": [],
  "LastModifiedOn": "2021-12-17T02:30:44.756+00:00",
  "LastModifiedBy": "myuser@mydomain.com",
  "Links": {
    "Self": "/api/Spaces-2/deployments/Deployments-51167",
    "Release": "/api/Spaces-2/releases/Releases-32966",
    "Environment": "/api/Spaces-2/environments/Environments-101",
    "Project": "/api/Spaces-2/projects/Projects-1201",
    "Task": "/api/tasks/ServerTasks-151426",
    "Web": "/app#/Spaces-2/deployments/Deployments-51167",
    "Artifacts": "/api/Spaces-2/artifacts?regarding=Deployments-51167",
    "Interruptions": "/api/Spaces-2/interruptions?regarding=Deployments-51167",
    "DeploymentProcess": "/api/Spaces-2/deploymentprocesses/deploymentprocess-Projects-1201-s-0-S3EQL",
    "Variables": "/api/Spaces-2/variables/variableset-Deployments-51167"
  }
}

That Json result shows that it thinks it is deploying only to Tenants-61 (line 61). A check of what Tenants-61 is shows that is the Blue tenant:

Summary
{
    "Id":  "Tenants-61",
    "Name":  "Blue",
    "TenantTags":  [
                       "Tenant/Blue"
                   ],
    "ProjectEnvironments":  {
                                "Projects-1025":  [
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-108",
                                                      "Environments-101",
                                                      "Environments-107",
                                                      "Environments-202"
                                                  ],
                                "Projects-1082":  [
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-107",
                                                      "Environments-101",
                                                      "Environments-108",
                                                      "Environments-202"
                                                  ],
                                "Projects-1121":  [
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-108",
                                                      "Environments-101"
                                                  ],
                                "Projects-1122":  [
                                                      "Environments-101",
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-108"
                                                  ],
                                "Projects-1182":  [
                                                      "Environments-101",
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-106",
                                                      "Environments-104",
                                                      "Environments-105",
                                                      "Environments-107",
                                                      "Environments-108"
                                                  ],
                                "Projects-1183":  [
                                                      "Environments-101",
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-106",
                                                      "Environments-104",
                                                      "Environments-105",
                                                      "Environments-107",
                                                      "Environments-108"
                                                  ],
                                "Projects-1184":  [
                                                      "Environments-101",
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-106",
                                                      "Environments-104",
                                                      "Environments-105",
                                                      "Environments-107",
                                                      "Environments-108"
                                                  ],
                                "Projects-1201":  [
                                                      "Environments-101",
                                                      "Environments-102",
                                                      "Environments-103",
                                                      "Environments-105",
                                                      "Environments-108"
                                                  ]
                            },
    "SpaceId":  "Spaces-2",
    "ClonedFromTenantId":  null,
    "Description":  "For Blue-Green Deployments",
    "Links":  {
                  "Self":  "/api/Spaces-2/tenants/Tenants-61",
                  "Variables":  "/api/Spaces-2/tenants/Tenants-61/variables",
                  "Web":  "/app#/Spaces-2/tenants/Tenants-61",
                  "Logo":  "/api/Spaces-2/tenants/Tenants-61/logo?cb=Tenants-61-2021042112340265"
              }
}

It SHOULD just be deploying to the Blue tenant.

The other weird thing, is that this works just fine for some other projects I have (that, as far as I can tell, are setup identically). I am a bit confused on how to proceed.

Why would this deploy to all my tenants when the call clearly says to only deploy to the Blue tenant?

Hi @OctopusSchaff,

Thanks for getting in touch! I’m sorry to see you’re hitting this very odd behavior. We gave this same Invoke-WebRequest a test, which was successful, e.g. it deployed only on the single defined tenant. I did notice a slight discrepancy in the Release IDs in your message which likely is just a typo but might be worth getting confirmation on: 'ReleaseId':'Releases-32965' in the command vs the result showing "ReleaseId": "Releases-32966".

Does deploying to this single tenant work another way, like with this script?

I look forward to hearing back and hopefully we can narrow this issue down!

Best regards,

Kenny

More comparing between projects got me the result. I mistakenly targeted the API call as the issue.

The core issue was that I had set up the lifecycle differently for this project. In that lifecycle, I had the first step be an auto deploy step. From what I can see auto deploy will deploy to ALL tenants. (Which is the reason I have an API call.)

Once I removed the auto deploy from the lifecycle’s first step, it all started working correctly.

Hi @OctopusSchaff,

Thanks for the update and for letting me know the result. Great to hear you got it sorted! Please don’t hesitate to reach out if you have any questions or concerns in the future.

Best regards,

Kenny