- Creating a Local Build With psake, Part 1: Compiling
- Creating a Local Build with psake, Part 2: Testing
- Continuous Delivery with psake and TeamCity - Reusing the Local Build to Create a CI Build
- Continuous Delivery with psake and TeamCity - Preparing for a pipeline
- Continuous Delivery with psake and TeamCity - Creating a pipeline with artifact dependencies
The first thing we have to do is to create a task that outputs a file with the build number:
task create_build_number_file { "$env:build_number" | out-file "$base_dir\build.number" -encoding "ASCII" -force } # Add this task as a dependency to ci task ci -depends compile, test, create_build_number_file$env:build_number is an environment variable set by TeamCity containing the build number of the running build.
Next we have to publish this file to the artifact repository. Add build.number to the Artifact paths in TeamCity:
If we now run the CI build we should see something like the following under the Artifacts tab of the build:
So far, so good! Next up is to read this file when we deploy to test and set the build number.
task set_build_number { $script:build_no = get-content "$build_artifacts_dir\build.number" TeamCity-SetBuildNumber $script:build_no } # Add this task as a dependency to deploy task deploy -depends set_build_number{ Write-Output "deploying to test!" } # Make sure to add this line after the properties declarations include .\..\tools\psake\teamcity.ps1TeamCity-SetBuildNumber is a helper function that is defined in teamcity.ps1 which comes bundled with psake.
We also have to tell TeamCity to download the build.number file when Deploy to Test is run:
If we run Deploy to Test the TeamCity dashboard should look similar to this:
We have now seen how we can visualize which build number is deployed to which environment. Happy days!
As always you can download the source from GitHub.