vs team services trigger build with commit message

1k views Asked by At

Background

I have a project set up in VSTS, which builds my solution and runs octopack to push the package to my octopus deploy feed. I am using a local build agent and a local octopus deploy server.

The build is currently manually triggered.

The project is worked on frequently, with multiple commits.

Branching is not currently used, there are various reasons for this, it's not ideal but it's what I have to work with for now.

The problem

Not all commits to the project should be deployed. CI triggers and scheduled triggers will result in multiple packages being pushed to octopus deploy. Not all of these will be release candidates.

I want to move away from manually triggering the build. The long-term goal is to have someone else run the octopus deploy release without my involvement.

The question

Is it possible to trigger either the VSTS build or octopack using commit messages?

If not, is there any other way of solving this problem, or am I stuck with manual triggers until I can sort the branching problems?

2

There are 2 answers

1
Eddie Chen - MSFT On BEST ANSWER

No, there isn't any way to trigger VSTS build or octopack via commit message.

The alternative way would be add a powershell task at the begin of your build definition to check the latest commit message. If the commit message contain the words to ask for build, then go on. Otherwise fail the build directly. However this will lead many failed builds. Or you can create one more build definition which triggered by commit. The definition only include one powershell task to check the latest commit message. When the commit message contains the words to ask for build, then trigger your original build definition via VSTS Rest API, otherwise, do nothing.

3
David Noreña On

Right now, 2 years after you asked this question this is the way I do it:

There is one predefined build variable $(Build.SourceVersionMessage), it'll give you the exact commit message, it's now documented in the official docs.

There is also a feature called Conditional Expressions, more info of them here.

With this in mind you can create a CI Pipeline that will be executed everytime you push a commit into your repository, but inside your task you can create the Conditional Expression inside the Control Options Tab that would execute some kind of "logic" to execute or skip the task, without failing the whole pipeline as you can see below:

Test-CI Pipeline

In my case I check if the commit contains the word FULLBUILD if so, I execute the task.

Condition: and(succeeded(), contains(variables['Build.SourceVersionMessage'], 'FULLBUILD'))

And these are the Pipeline execution logs when the condition is succeed or failed (without failing the whole pipeline :D).

Condition Succeed: Test-CI-ConditionSucceed

Condition Failed: enter image description here

Hope it helps some one :)