Teamcity environment variables
You must remember to set the parameters in the build configuration before hand.
Teamcity environment variables how to#
This example showed how to do so using Source Code entered directly in the script block for PowerShell and there is a slightly different technique if it is PowerShell scripts that need to use the input parameters. Process exited with code 0īeing able to set and pass parameters between build steps in TeamCity is really useful and makes the builds much more flexible. Han Solo was one of the pilots of the Millennium Falcon. In the film A New Hope there is a starship called the Millennium Falcon. Here are the populated parameters that were set in the build configuration as empty: Command: /opt/microsoft/powershell/6/pwsh -NoProfile -NonInteractive -File /opt/TeamCity/buildAgent/temp/buildTmp/powershell1234487986819058447.ps1 Working directory: /opt/TeamCity/buildAgent/work/74e814b1d9185321 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:
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. This post will show how to set and pass variables in PowerShell TeamCity build steps.