Suppose I have a project A which has 3 or 4 major process steps and one environment defined in its default lifecycle.
It also has a prompted variable called FeatureID whose value I set when invoking octo.exe create-release, passing it a value like so: --variable “FeatureID:$(Build.SourceBranchName)”. I’m not receiving an error during release creation, but am receiving an error on the first step of my deployment process. This first step is a “Run Azure Powershell Script” step type and it makes use of several variables
from a variable set called “Azure Deployment Settings”. Variable assignment/binding is as follows:
dnssuffix = cloudapp.azure.com
region = eastus2
resourcegroup = automationtests
dnsnamepattern = replaceme.#{region}.#{dnssuffix}
I have defined an azure resource manager service principal and that works fine as well.
The script body is as follows:
$resourceGroupName = #{ResourceGroup}
$regionName = #{Region}
$virtualMachineName = #{FeatureID}
$rawDnsNamePattern = #{DnsNamePattern}
$virtualMachineName = $virtualMachineName.Replace(“features/”,"")
$calculatedDnsName = $rawDnsNamePattern.Replace(“replaceme”, $virtualMachineName)
Write-Host “ResourceGroup is $resourceGroup”
Write-Host “Region is $region”
Write-Host “VirtualMachineName is $virtualMachineName”
Write-Host “PublicDnsName is $calculatedDnsName”
$vm = Get-AzureRmVM -ResourceGroupName $resourceGroup -Name $virtualMachineName -ErrorAction SilentlyContinue
if ($vm -eq $null)
{
Set-OctopusVariable -name “TargetVMSearchResult” -value “Found”
Write-Host “Found host: $calculatedDnsName”
}
else
{
Set-OctopusVariable -name “TargetVMSearchResult” -value “NotFound”
Write-Host “Did not find host: $calculatedDnsName”
}
This is the error I am getting in the task log. Am I referencing/accessing the variables incorrectly in Write-Host ? My
intent here is to echo the variables I’m setting to the task log and also set an output variable in step1. If the VM is found,
using the $calculatedDNSName (FeatureId.eastus.cloudapp.azure.com, for example), then I would proceed with step 2
and deploy the package. If however, it’s not found, then I would like to fire an email or a manual intervention step so the VM
can be created.
Unpacking Calamari.Azure version 3.3.5 to ‘D:\Octopus\Calamari\Azure\3.3.5’
Environment : AzureCloud
Account :
TenantId :
SubscriptionId :
CurrentStorageAccount :
Account :
Environment : AzureCloud
Subscription :
Tenant :
eastus2 : The term ‘eastus2’ is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\Octopus\Work\20160412222235-2\Script.ps1:2 char:11
- $region = eastus2
-
~~~~~~~
- CategoryInfo : ObjectNotFound: (eastus2:String) [], ParentContainsErrorRecordException
- FullyQualifiedErrorId : CommandNotFoundException
The step failed: The remote script failed with exit code 1