Custom DeployToAzure.ps1 not working

Hi,

To be able to add the diagnostics extension right away when deploying my package I am trying to use a custom ps script.

I am using this one as a template: https://github.com/OctopusDeploy/Calamari/blob/ce3b69e94b60c8c73619bc584eca52e11c68930a/source/Calamari.Azure/Scripts/DeployAzureCloudService.ps1

I have included the script in my nuget package.

Without modifying anything in that template I get the following error (it worked before without providing the custom script):

Invoke-Expression : Cannot validate argument on parameter ‘SubscriptionName’.
The argument is null or empty. Provide an argument that is not null or empty,
and then try the command again.
At D:\Octopus\Work\20160831114825-1417\staging\Octopus.AzureContext.ps1:86
char:2

  • Invoke-Expression ". $OctopusAzureTargetScript $OctopusAzureTarge ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:slight_smile: [Invoke-Expression], ParameterB
      indingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
      Shell.Commands.InvokeExpressionCommand
      Script ‘D:\Octopus\Work\20160831114825-1417\staging\DeployToAzure.ps1’ returned non-zero exit code: 1
      Running rollback conventions…
      Script ‘D:\Octopus\Work\20160831114825-1417\staging\DeployToAzure.ps1’ returned non-zero exit code: 1
      The step failed: The remote script failed with exit code 1

Any idea what might be wrong?

Hi Björn,

Thank you for reaching out! This is the error you’re seeing:

Invoke-Expression : Cannot validate argument on parameter 'SubscriptionName'.

This is due to the fact that ‘SubscriptionName’ is no longer supplied, and that script you’re using as a template is a little out of date now. Using a later version of the script as your template instead should get you going!

Let me know how you go,

Kenny

Hi Kenny,

Thanks for quick reply.

I’m not quite following you.
In the DeployAzureCloudService.ps1 it says “When the script is run, the correct Azure subscription will ALREADY be selected”.

I haven’t executed any AzureContext.ps1 script on my own, but only added the DeployAzureCloudService.ps1 script in my nuget package.

So if I understand you correctly I also need to include the AzureContext.ps1? Or should I contact my Octopus Deploy admin to update that on the server?

We are using 3.3.19 version.

Thanks again,

Best regards,

Björn

Hi Björn,

I apologize. We (well, I) made a mistake and supplied you with a link to AzureContext.ps1. The link I meant to provide you was to the latest version of DeployAzureCloudService.ps1.

You’ll see that the SubscriptionName parameter is no longer provided.

The AzureContext.ps1 script is relevant though, as I believe it was the reason the SubscriptionName parameter was removed. I can’t recall exactly the technical details, but I believe it was related to the fact that we now use the New-AzureProfile cmdlet to create the profile, and it possibly doesn’t accept SubscriptionName as a parameter.

Did you particularly require the SubscriptionName?

Again, I apologize for the confusion.

Regards,
Michael

Thank you!
The updated template didn’t have “Set-AzureSubscription” at the beginning of CreateOrUpdate()-method. Which I guess was what was causing the issue.
The new template works as expected.

You may want to update that template link on this page, http://docs.octopusdeploy.com/display/OD/Deploying+a+package+to+an+Azure+Cloud+Service

Have a nice day,

Best regards,
Björn

Hi Björn,

Great to hear it’s working now! And thank you so much for pointing out the outdated link in our docs. I went ahead and updated it. Sorry again about that mix up!

Kind regards,

Kenny

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.