TeamCity Build & Deploy: How do you pass dependent artifact paths to a script?

12,088

We do something like this. It is not 100% clear but it looks like you want to do the build and deployment as two separate builds in TeamCity with an artifact dependency from the deployment build on the main build which is exactly what we do. Here is how we do it.

  • Setup your artifacts from the main build which it sounds like you have already done.

    Example: **\bin\release\*.* => bin
  • Set up the artifact dependency (we also do a snap shot dependency as well but you don't have to) to pull your artifacts from the main build and put them into a local folder in your deployment build.

    Example: Artifacts paths: bin\**\*.* Destination path: bin\
  • We use a mixture of MSBuild and PowerShell for doing the actual deployment work. In each case you can reference the artifacts using a relative path.

    IF the build work folder looks like this:

    root
     |- bin (Artifacts pulled in from main build)
     |- src
     |- build (Where your build and deployment scripts live)
    

    You would access the bin files from your deployment script located in the build folder like:

    ..\bin\[your files]

You can then pass the path to your build artifacts like this

%teamcity.build.checkoutDir%\bin\
Share:
12,088
David Hayes
Author by

David Hayes

Expert .NET developer with broad experience in Java and other languages/platforms

Updated on June 03, 2022

Comments

  • David Hayes
    David Hayes almost 2 years

    How do you pass the artifact paths to a script in TeamCity. The scenario is this

    1. Build Project
    2. Deploy Project (with an artifact dependency to #1)

    Step 2 consists of a a script which

    1. Stops a service (to unlock files)
    2. Copies the build artifacts to the server
    3. Restarts the service

    I'm struggling with step 2, I figure I need to pass the path of the build artifacts into the script but I can't see how you do it?

  • David Hayes
    David Hayes about 12 years
    Thanks, I think the bit I hadn't completely understood was how the artifact dependency pulled the build artifacts into its working directory %teamcity.build.checkoutDir%\bin\ was the path I needed. TeamCity is great but some of the documentation is a little inscrutable
  • Bronumski
    Bronumski about 12 years
    You don't need the %teamcity.build.checkoutDir% variable bin\ would be fine but if it makes it clearer for maintenance then all the better.
  • David Hayes
    David Hayes about 12 years
    If you're using powershell add "-ExecutionPolicy bypass" to the commandline, setting the policy on the machine doesn't appear to work (oddly)
  • David Hayes
    David Hayes about 12 years
    I'll try it without but my Powershell script needs the full path or will TeamCity expand it out for me?
  • Bronumski
    Bronumski about 12 years
    TeamCity will be able to use relative paths but you need to tell powershell to set it's environment to be a specific path to do relative paths it does not treat the paths as relative to the running powereshell script file.