

- #Teamcity environment variables how to
- #Teamcity environment variables update
- #Teamcity environment variables code
PowerShell Executable: /opt/microsoft/powershell/6/pwsh PowerShell running in non-virtual agent context Here is the output from the build log: Step 4/4: Putting it together (PowerShell) %pilotName% was one of the pilots of the %starShipName%. PilotName = Write-Output -InputObject $params Write-Output " `n In the film %film% there is a starship called the %starShipName%. $params = are the populated parameters that were set in the build configuration as empty:
#Teamcity environment variables code
Script Source: See code under each build step heading below.Execute Step: If all previous steps finish successfully.I’m using PowerShell Core Version 6.1.1 running on Ubuntu but this will work on PowerShell desktop too. Where the steps differ is in the source code box which I’ll set out separately. Here are the general build settings for each step.

As noted in the TeamCity documents, the modified values of the parameters will be available in the build steps that follow (if you need to use them in the current build step, assign them to a variable in that script before using that variable to set the system message value). This demo breaks down querying the Star Wars api into different build steps just to demonstrate the passing of parameters (you could easily do this in one step!). "#teamcity" Updating the parameters with PowerShell

However, in PowerShell # is a comment so you must enclose the statement in double quotes. The documents show the following example for setting parameters: #teamcity Now the parameters are set up, they can be updated in the scripts or source with service messages. filmUrl - string (used as the first call to the Star Wars API).I have tested and found these work well and you don’t need to prefix them like the environment and system variables. I am using the configuration parameters throughout. There are 3 types of parameter in TeamCity:
#Teamcity environment variables update
You can also create empty parameters and update them to pass values between individual build steps. TeamCity ParametersĬreating parameters is a great way for creating flexible build steps and making them more reusable. It uses retrieving Star Wars data from the swapi Star Wars API as an example of getting data with PowerShell, setting a variable in a build step and using it in the preceding build steps.
#Teamcity environment variables how to
This post will show how to set and pass variables in PowerShell TeamCity build steps. Updating the parameters with PowerShell.Or, if using Psake, modify the script above to return you a hashtable which you can pass directly to Psake's -properties argument.Updating TeamCity build step parameters using PowerShell , and if you load the XML version it's fairly easy to loop through and push them all into scope (though you do get everything as a string of course). , or looped over and pushed into variable scopeĪccess the build properties file that TeamCity makes available during the build.

Use environment parameters, which can be accessed explicitly within PowerShell using , but in the meantime you can do one of the following:Įxplicitly map any of the TeamCity build properties to script parameters using the parameter expansion that's available within the Script Source box. It's occurred to me to write a psake-optimized build runner that In the case of the Powershell script runner, when using a script file, they don't propagate down to your scripts. As it says in the TeamCity documentation, the system parameters are passed to the build script runner, but not all build script runners know what to do with them.
