Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Travis-CI build_number within after_script command

How can one get the build_number (and other build metadata) from within the after_script command in Travis-CI?

What have been tried already:

The documentation on build configuration says this, in the IRC notification section:

You also have the possibility to customize the message that will be sent to the channel(s) with a template:

notifications:
  irc:
    channels:
      - "irc.freenode.org#travis"
      - "irc.freenode.org#some-other-channel"
    template:
      - "%{repository} (%{commit}) : %{message} %{foo} "
      - "Build details: %{build_url}"

You can interpolate the following variables:

  • repository: your GitHub repo URL.
  • build_number: build number.
  • branch: branch build name.
  • commit: shorten commit SHA
  • author: commit author name.
  • message: travis message to the build.
  • compare_url: commit change view URL.
  • build_url: URL of the build detail.

Trying to get this to work within an after_script command as below, did not work at all:

language: java
after_script:
  - git commit -a -m "Committed by Travis-CI build number: %{build_number}"

It behaved as if .travis.yml file was absent/invalid (even though it did pass the Travis-CI YAML validation here).

It seems as though this should be doable, but could not find any sample that does this.

Could someone point me in the right direction?

like image 775
Hari Pachuveetil Avatar asked Sep 28 '12 15:09

Hari Pachuveetil


1 Answers

The string replacements you can do for IRC output only work there unfortunately. They're only meant to be used for notifications in general, to customize the output, but are currently only available for IRC.

There's still a way to get the current build number, by accessing the TRAVIS_JOB_ID environment variable. If you change your script to the following line, things should work as expected:

after_success:
  - git commit -a -m "Committed by Travis-CI build number: $TRAVIS_JOB_ID"
like image 151
roidrage Avatar answered Oct 25 '22 11:10

roidrage