On March 29th, 2017 the VSTS team released a new feature that added the ability to specify conditions for running a build task. This provides more control over your build tasks, for things such as a task to clean things up (even if a build fails), or send a message when something goes wrong, under conditions such as certain branches or with certain triggers. Custom Conditions appear in the new build definition editor under Control Options. Custom conditions are not currently available for Task Groups because they still use the old build definition editor (this is on the backlog).
Microsoft provides examples for various conditions here: https://www.visualstudio.com/en-us/docs/build/concepts/process/conditions
I found the most useful condition was checking variable values, in particular, the build.reason variable. I used this to combine multiple build definitions into one by setting conditions on certain tasks so they only ran based on what triggered the build. I had a separate build definition for CI (compilation and unit tests only) that was triggered by pull requests. Setting the following condition, the compilation and unit tests would run if the build was triggered by a pull request:
and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
I had another build definition that would run CI, along with packaging and pushing packages to our artifact repository. By setting the build conditions I could combine the two definitions and only run the extra steps to package and push if the build was manually queued or scheduled as part of our nightly build.
Note: I encountered a bug where conditions do not save the first time. Reload the build definition editor, re-enter the conditions and they should save the second time around.
Have you used custom conditions? Leave a comment below!
Hello All,
I have list of build definitions and each has different Build Number Format(Total 3 types of build format). So I want to set a release definitions, but it will check correct build number format then only start deployment in VSTS. Can anyone help me ?
Thakkar,
Are you saying you want to trigger a release if the build number format matches a Custom Condition? I’m not sure what formats you’re working with but you could probably come up with something using the functions here: https://www.visualstudio.com/en-us/docs/build/concepts/process/conditions#general-functions
To simplify things, would it be possible to trigger a release based on the build definition name? If so, the condition would look something like “and(succeeded(), eq(variables[‘Build.DefinitionName’], ‘BUILDDEFINITIONNAME’))”
Hopefully that helps,
Marcus
I want to trigger a build based on any changes in particular folder(this is in context with yarn workspaces packages)..can u help plz.
Take a look at the build pipeline triggers doc: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml
Hello Marcus,
I we have three build definitions that need to be complete first and after that successful build of all the three build defination. i want to trigger after completion of three build pipeline as this pipeline for packaging pipeline to create the singe exe our application to deploy to the servers. can you help me what type custom condition do i need to use.
Hey Saipavan,
That sounds like a good fit for pipeline completion triggers. Give that a shot and let me know if you have any other questions.
Marcus