I am using Octopus for getting my environment ready with all prerequisites. In one of the octopus step I want some varaibles values to be set dynamically for which I have used the octopus output variables.
If I want to declare the output variable in form of an array, its value not getting read in other step where I want to read that.
Below are few code snippets which I have used (Note : both the steps are having inline powershell script code written):
/*Step A code : Set output variable of step code*/
$market= "RO" /*Dynamically identify market depends on machine name */
write-host $market
Set-OctopusVariable -name "TestResult_Domain_['+%market%+']" -value
"DomainNameOfMachine"
/*Another step code*/
$market= "RO" /*Dynamically identify market depends on machine name */
write-host $market
$filterDomain = "Octopus.Action[StepA].Output.TestResult_Domain_['$market']"
Related
I am trying to assign value to built-in release notes variable in "Run a Script" step.
$OctopusParameters["Octopus.Release.Notes"] = "Some release notes"
In the next step "Send an Email" I am using this variable in email body, but unfortunately it is empty.
<p>#{Octopus.Release.Notes}</p>
Is it possible to set Octopus Deploy system variable value from PowerShell and use it in the next step?
I am using Octopus Deploy 3.7.11.
EDIT:
I have also tried the cmdlet Set-OctopusVariable and it did not work.
Set-OctopusVariable -name "Octopus.Release.Notes" -value "Something"
I don't think it is possible to overwrite values of the built-in variables provided by Octopus Deploy. But you could define your own output variable and refer to that in the following steps. For example in your 'Run a script'-step use:
Set-OctopusVariable -name "MyReleaseNote" -value "Some text here"
Then the "Send an Email"-step can refer to this text by using the following (assuming the first step is called 'FirstStep'):
#{Octopus.Action[FirstStep].Output.MyReleaseNote}
The variable can also be used from a script in other steps, then use the syntax:
$relnote = $OctopusParameters["Octopus.Action[FirstStep].Output.MyReleaseNote"]
(If you want to save the generated releasenote perhaps you could save it as an 'artifact' in the project).
I tried this using Octoposh. Modifying an existing variable is covered in the Octoposh wiki at Modifying Variables - Edit a variable of a Project/Library variable set.
I wasn't able to get this to work because of timeouts on our network, but it looks like it should work - just not as straight-forward as I expected.
The Xcode archive step creates this variable: ${BITRISE_DEPLOY_DIR} and read that pilot uses the PILOT_IPA environment variables for the IPA directory.
Is there a way to assign the output (BITRISE_DEPLOY_DIR) to another environment variable (e.g.: $PILOT_IPA)?
You can do that by using envman (https://github.com/bitrise-io/envman) which is part of the bitrise CLI tool stack.
To assign the value of an existing Environment Variable (Step outputs are just regular Environment Variables) you can use a Script step, and specify this as the content:
#!/bin/bash
echo "BITRISE_DEPLOY_DIR: $BITRISE_DEPLOY_DIR"
envman add --key PILOT_IPA --value "$BITRISE_DEPLOY_DIR"
This'll first print the value of the BITRISE_DEPLOY_DIR environment variable, and then with envman add it'll add a new environment item with the key PILOT_IPA and the value of $BITRISE_DEPLOY_DIR.
we have Octopus-2.0.
We stored the service credentials (they are per machine) in octopus user variable.
I need to create these login in SQL server as well.
For Example service login name "machine1_service1" stored as variable name. and password of that login is stored under column Variable Value in octopus.
so far i know that to any variable value from octopus we need to provide exact variable name. but in this case I actually need to get list of all these variables.
Is there a way to accomplish this?
Yes.
Octopus variables are accessible from a dictionary object that can be enumerated. If you follow a naming convention you could query the dictionary using powershell with something like the following. This would be called from within a custom step or somewhere where you can write your own powershell e.g. a PostDeploy.ps1 script in the .nuget file
Let's say the variables are defined like this
You can use this powershell to get to them and enumerate round them
# Get service accounts
$serviceAccounts = $OctopusParameters.keys | ? {$_ -like "service-*"}
write-host "Accounts found:" $serviceAccounts.count
foreach($account in $serviceAccounts)
{
write-host "Account: $account"
$password = $OctopusParameters[$account]
write-host "Password: $password"
}
Hope this helps.
I have created a parameter in Team city that is system parameter as shown below
system.version and its value is gla so it is like
system.version=gla
now can you please advise in Team City how can I configure this variable such as i want date time stamp to be appended since this variable is need to be changed every time when my build runs so I want to add the dates time stamp to this system variable please advise how to achieve this in team city.
You can add an initial build step that writes out a service message to update the parameter value (example below in PowerShell):
Step 1
$date = Get-Date
Write-Host "##teamcity[setParameter name='system.version' value='gla$date']"
Step x
Write-Host '%system.version%' # will output the new value
You can write a custom build step that calls a shell command and appends date/time to your variable
#!/bin/bash
date_var=`date +%Y%M` --> Define your format here
echo "##teamcity[setParameter name='system.version' value='$date_var']"
PS: you can use the new value of your variable only from the next build step
I need to create a logon script that lists the following values for each PC
(P+IPAddress) & (S+IPAddress), I managed to create the following .reg file:
HKEY_CURRENT_USER\Serial Numbers
"Printer"="P236"
"Scanner"="S236"
But I have entered these values my self, I need a script that creates a combined value (Letter + The last 3digits of the IP Address of the PC where this script runs).
I highly appreciate it if someone can help me on this.
If you want a single command, use Powershell like this:
powershell -Command "& {[system.net.dns]::gethostaddresses([system.net.dns]::gethostname()) | where { $_.addressfamily -eq 'InterNetwork' } | foreach { [microsoft.win32.registry]::setvalue('hkey_current_user\serial numbers', 'Printer', [string]::concat('P', $_.tostring().split('.')[3])) } }"
Not the most efficient and may have problems with multiple addresses (as it will always set to the last one) but it can be executed as a single command.
Should be easy enough to modify that command to add the Scanner bit too.