Using Build Number from Artifact Dependency after Trigger

Answered

TLDR: I just want to use the same build number along our pipeline.

I have a build configuration called "Core - Checkout and Build" that gets our code from Git and builds.

After this has successfully finished I'd like to trigger a platform specific build (in another project) and use the Build Number from the "Core - Checkout and Build".

I have successfully done this by setting the "Build number format:" to... %dep.CoreCheckoutAndBuild.build.number%

This works if the Artifact Dependency is set to depend on the "CoreCheckoutAndBuild", getting the artifacts from "Latest successful build" and building branch <default>. This is fine BUT the default branch is our development branch and therefore it just keeps building the development branch and not our feature branches.

Changing the "Build branch" to: <active> causes a <value is required> for the "dep.CoreCheckoutAndBuild.build.number" parameters.

I can't see why it no longer knows this Parameter I change the dependency from <default> to <active> branches.

When I manually select the dependency for our build it also works.

0
1 comment

So first of all, if you want to keep the "build number" across the pipeline, I'd assume that you want to build all the configurations as a chain. If this is the case, then use snapshot dependencies. When you trigger a build B, it will automatically add to the queue a build for all of its snapshot dependencies. Snapshot dependencies also always satisfy the parameters because either a build already exists that is taken to run the chain (if you configured it that way), or a new one will be created

Retrieving parameters from artifact dependencies requires that TeamCity first locates a build from "CoreCheckoutAndBuild" that matches the branch specified on the branch field (and <active> here means literally the branch '<active>', not the active branches). Then, the parameters and artifacts are picked up from it that build. It will *not* run a build on that branch if there isn't a successful one already, and if the branch doesn't exist in the initial build it will fail to load the parameter and thus it won't start. That's what snapshot dependencies are for (and why i mentioned them before)

With this in mind, what you can do if you don't want a snapshot dependency, is either configure the artifact dependency to always grab the artifact from a given branch on CoreCheckoutAndBuild, or set up the branch name on the dependency as another parameter (%dependency_branch_name% for example), then you will need to set the branch name to pick up the dependency from when you want to run a build. If the branch names in both configurations always match, then you can use %teamcity.build.branch% as the parameter instead, and if you run the build on branch xyz, then it will pick an artifact and parameters from the last successful build from branch xyz on CoreCheckoutAndBuild, given that a successful build on that branch exists

A quick note on this approach. The build configuration will *still* tell you that you need to set the value for %dep....%, but if you hit run, it should actually run, because it will pick up the values for the variables when resolving the builds and everything should fall into place.

0

Please sign in to leave a comment.