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?
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With