Description
I am trying to automate Azure deployment from a Bamboo OnDemand Amazon EC2 Elastic Instance. Unfortunately, I've hit a bump in the road and I'm not quite sure why or how to solve it.
As an example, I tried the following script:
Write-Output "Importing Azure Module"
Import-Module Azure
Try {
Write-Output "Importing Azure Publish Settings"
Import-AzurePublishSettingsFile "C:\Users\Bamboo\azure2.publishsettings" -ErrorAction Stop
}
Catch {
Write-Output "An error occurred"
Write-Output $_.Exception.Message
Write-Output $_.Exception.ItemName
Write-Output $_.Exception.StackTrace
exit 1
}
The exception info:
27-Nov-2014 19:01:05 Importing Azure Module
27-Nov-2014 19:01:05 Importing Azure Publish Settings
27-Nov-2014 19:01:05 An error occurred
27-Nov-2014 19:01:05 An internal error occurred.
27-Nov-2014 19:01:05
27-Nov-2014 19:01:05 at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
27-Nov-2014 19:01:05 at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
27-Nov-2014 19:01:05 at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
27-Nov-2014 19:01:05 at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password)
27-Nov-2014 19:01:05 at Microsoft.WindowsAzure.Commands.Utilities.Common.PublishSettingsImporter.PublishSubscriptionToAzureSubscription(ProfileClient azureProfileClient, PublishDataPublishProfile profile, PublishDataPublishProfileSubscription s, String environment)
27-Nov-2014 19:01:05 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
27-Nov-2014 19:01:05 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
27-Nov-2014 19:01:05 at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
27-Nov-2014 19:01:05 at Microsoft.WindowsAzure.Commands.Common.ProfileClient.ImportPublishSettings(String filePath, String environmentName)
27-Nov-2014 19:01:05 at Microsoft.WindowsAzure.Commands.Profile.ImportAzurePublishSettingsCommand.ImportFile(String fileName)
27-Nov-2014 19:01:05 at Microsoft.WindowsAzure.Commands.Profile.ImportAzurePublishSettingsCommand.ExecuteCmdlet()
27-Nov-2014 19:01:05 at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
27-Nov-2014 19:01:05 Failing task since return code of [powershell -ExecutionPolicy bypass -Command C:\Users\Bamboo\AppData\Local\Temp\2457601-2555906-2752561-ScriptBuildTask-1993266622499637567.ps1] was 1 while expected 0
27-Nov-2014 19:01:05 Finished task 'Deploy' with result: Failed
This script is invoked through the build system with the following command:
powershell -ExecutionPolicy bypass -Command C:\Users\Bamboo\AppData\Local\Temp\2457601-2555906-2752561-ScriptBuildTask-1993266622499637567.ps1
The weird part is that, if I RDP onto the VM with the bamboo
user and run the Import-AzurePublishSettingsFile "C:\Users\Bamboo\azure2.publishsettings"
manually every following execution of the build script succeeds and prints out the result of the Import-AzurePublishSettingsFile
call.
In order to save costs, the build server is set on a schedule to shut down between 8 PM and 7 AM which means that currently someone has to log on onto the virtual machine every day and run the command manually before any deployment succeeds. It's understandable that this is becoming a burden on our deployment process.
I know that Bamboo might be a factor in this, but I would like to understand what could be the problem and why this could occur. Could it be something with the way the script is invoked, is there a PowerShell command I must run to elevate certain permissions, ...
Thanks