Default Branch mapping not working as expected

Hi,

i use a configuration that assigns an explicit branch mapping as the default branch for the configuration. However, an assigned trigger does not function as expected.

To be clear:
Edit/Repository/Branches/Default Branch => master
Mappings/Default Branch => release/x.y

The trigger is configured to “Trigger on Default Branch”.

I push a git commit on release/x.y. The trigger does not fire, but it should.
I push a git commit on master. The trigger starts a build :frowning:

Note, this issue is related to my post here:

Hi Thomas,

When a Repositories Trigger is set to trigger on the default branch, this means that it will trigger on the default branch set in the repository settings.

The Default Branch mapping is only used when manually starting a build.

image

It is also used for to define the branch to build for other non-triggering repositories in the same configuration, so I can see how you might expect this to work differently.

This will need some clarification in the UI. We wouldn’t want to change the behaviour now as this may break builds for other users, but we will look into adding another option to the Trigger On drop-down which takes the branch mappings into account.

Hi Dave,

indeed, when opening the queue dialog, the mapped branch will be the default. It was an oversight on my side, that the configuration is used for manual builds only.

We use a simple branch model with master as the integration branch, into which feature branches will be merged by a merge-commit. Thus, master is the branch which contains the next version of our product(s) currently under development.

Since we maintain at least one version in production, we create a release-branch for every released version. We therefore setup two configurations: dev and release/m.n. Configuration “dev” builds on master and topic branches. Configuration “release/m.n” builds on the release branch. For example when a service pack needs to be deployed. Any time a commit is pushed to the server, the trigger is used to build that specific commit. Thus, releasing developers of the burden of manual builds and automatically provide builds for our continuous integration pipeline.

The dev and release configurations are very similar. They share the same repository, but use a different version format string and build number. An event is used to create tags on the release branch, which uses a condition of the event handler to act upon the release branch only. As mentioned by you, the requirement is to support an automatic trigger that takes the branch mapping into account. Having another option to the Trigger On drop-down would satisfy this requirement.

I can now see how this would allow to even simplify the configuration further. By adding a “Conditions” tab to the trigger (as used by event handlers), we could create triggers for dev and release within one single configuration and assign the specific version string by the “Variables” tab offered by the trigger configuration.

Hm…, but how to configure the buildnumber, which is different to dev and release branch?

While you can’t change the $Build.BuildNumber$ during the build, you can use other “number” variables as “branch build number” counters and use the Persist Build Variable event handler to increment and save the relevant variable at the start of the build. You can then use these variables in the Set Build Version actions with some If … Else logic to choose the variable and format to use based on the current branch. Note that this can have unexpected results if builds run at the same time, so I would link the Persist Build Variable event handler to a short initial stage with a shared resource lock added to it to prevent it from running concurrently.

Alternatively, you could add more than one triggering build configuration (one for each of the dev and release branches) which contain nothing but repository triggers, then use a Build Completed Trigger to trigger and pass on the build number and version string your main build configuration.

What would you put in the Conditions tab that is not covered in the other tabs?

Hi Dave,

thanks a lot for your explanation on the subject. It is an interesting approach. It does extend my ability to work with Continua, as my understanding using configurations and triggers is set to a new level :slight_smile:

My experience by using a Buildsystem such as ContinuaCI is, that build configurations change over time. Either because of new requirements, new insights on Continua or changes in the tool chain. Therefore when releasing a new product version we rename ‘dev’ configuration to ‘release x.y’ and create a new ‘dev’ clone configuration. Doing so gives us ‘versioning’ of configurations. This concept allows for simple configurations and is efficient also.

The procedure requires some changes to the configurations, such as:

  • setting up the version string
  • configure the branch mapping
  • configure the trigger

The trouble is to have all team mates keep up to date on the procedure. Thus my goal is to reduce the steps necessary to release a version.

For example, the configuration includes an event handler to create tags on the release-branch. The event handler is enabled for the configuration, but fires only for the release-branch. This is achieved by a condition doing a string compare on the branch-name.

As described the mechanism used for event handlers in my previous answer, I’d use a string comparison on the branch-name. This would allow the trigger to exist on a project scope, but triggering only, on specific configurations.

Hi Thomas,

Other than having a trigger which executes on the default branch mapped for the configuration, which we will implement, I’m not quite clear what additional features you are asking for.

Triggers already have the ability to be conditional on the repository branch name. If you select “Pattern matched branches”, then you can enter a pattern or a variable containing a pattern to match against the branch name.

e.g.

I can’t see what we could put in a trigger Conditions tab, which would not be a duplication of the existing functionality.

I’m also not sure what you a looking to do with the build number (and version string). I previously thought that you were trying to have different build numbers for different branches on the same configuration, but it now appears that you are using a new configuration for each branch.

If the aim is to reduce the number of steps after cloning a configuration, then perhaps it would be better to use variables to define the things that change so they can be edited in one place.

Can you provide some examples of the changes that you would like to see to support your scenario?

Hi Dave,

my intention is to disable a trigger by setting a “Condition”.

Consider the following configuration:
trigger #1 triggers on the default (repository) branch
trigger #2 triggers on the default mapping branch (planned for one of the next Continua versions).

If both point to “master”, which is the default, unless configured otherwise, will they both trigger a build?

Yes, but only if a changeset is detected on branch “master”.

What is the condition?

Hi Dave,

thanks for your support. Let’s try a different approach and restart.

Requirements

  • have one configuration for development on branch “master”
  • support multiple configurations on release branches, e.g “release/1.0”, “release 1.1”, etc.
  • trigger dev configuration for any branches, that are not a release branch
  • trigger the appropriate release configuration for the matching release branch
  • manually queuing a build must point to the appropriate branch
  • only minimum changes required when releasing a version

Comments

  • a release means renaming dev to release/x.y (to keep build history) and clone that back to “dev”
  • i tried to achieve this by using the repo default branch and configuration mapping branch respectively

Hi Thomas,

Which of these requirements are you currently unable to meet?