Trigger a specific commit via the Travis API

I’m looking at triggering builds through the Travis API. Am I right to assume it’s not possible to trigger a specific commit? It’s only possible to build the latest on a specific branch?

Yes, it’s only possible to specify branch names (more specifically, valid remote refs).

I’ve tried supplying a SHA-1 instead as branch and a build was created. But the supplied name is being passed to git clone --branch and the cloning thus failed.

Nothing prevents you from creating a topic branch at any commit though.

(See also for what valid input is in Git terms.)

Yeah, that’s what I thought.

I’ve worked around this by triggering the API with specifically checking out the correct commit in the install stage:

  "request": {
    "message": "(${TRAVIS_COMMIT:0:7}) $TRAVIS_COMMIT_MESSAGE",
    "branch": "$TRAVIS_BRANCH",
    "config": {
      "merge_mode": "replace",
      "language": "java",
      "jdk": "openjdk12",
      "install": "git checkout -f $TRAVIS_COMMIT",
      "script": "./",
      "env": {
        "global": [

(I have sanitized the TRAVIS_COMMIT_MESSAGE for json consumption)

This is far from a perfect solution, but it kinda works.

Caveat: The git commit SHA shown in the Travis UI will always be the latest one, and that might not match the commit I checked out in the install stage. That’s why I’ve added it to the message.