Search code examples
teamcityperforcebuild-automation

A way to commit TeamCity build products to Perforce?


Building works fine but the last thing puzzles me... how to commit build products back to the P4 repository? It doesn't look like there's no pre-defined setting or build step/feature for that?

It's super-weird to me that I would have to write my own script for that... Is this what require, how I would make my pre-defined P4 workspace to submit binaries?


Solution

  • OK, first I realize that "artifacts" thing is something to use when deploying ready-to-use applications, not just binaries.

    Skipped deploying artifacts and simply added a new build PowerShell build step. It's not perfect yet, storing the password in plain text, but this basically works. Couldn't force to work while skipping P4 "login" at every command. P4 was replying with the message "Password was invalid or unset".

    $user ="MyUser"
    $workspace ="MyWorkspace"
    $pswd ="MyPassword"
    
    # update workspace root - use human-friendly workspace name instead of TeamCity automatically generated workspace
    $p4Client = p4 -c $workspace -u $user -P $pswd -p localhost:1666 client -o $workspace
    $p4Client = $p4Client -replace '^Root:.+$', "Root: %teamcity.build.checkoutDir%"
    $p4Client | p4 -c $workspace -u $user -P $pswd -p localhost:1666 client -i
    
    # submit build products
    p4 -c $workspace -u $user -P $pswd -p localhost:1666 reconcile _a -e -c default "//..."
    p4 -c $workspace -u $user -P $pswd -p localhost:1666 submit -d "build %build.number%"