How to define variable in travis CI that will store Github command

I am trying to create a CICD Pipeline using Travis CI, in which I am creating a tag on my Github using mvn release plugin.

After creation of a tag, I want to deploy the file created under the tag on my environment. The tag name and the file name is same. For example, demo-1.0.1-app.jar and tag name is also the same, demo-1.0.1-app. The file is created under the target folder and I am able to deploy it using a maven command mvn deploy -Dartifact=target/demo-1.0.1-app.jar.

But to automate this I was trying to create a variable in the travis.yml file which would contain git command git describe --abbrev=0 --tags so that I can pass this variable as file name:

env: 
      - version = $(git describe --abbrev=0 --tags) 

in my script like this: mvn deploy -Dartifact=target/$version.jar

But while running the filename is coming as blank. Please suggest what needs to be done.

In a tag build, the tag’s name is available as $TRAVIS_TAG.
So there’s no need to run any Git commands to retrieve it.

See https://docs.travis-ci.com/user/environment-variables/#convenience-variables.


If you are rather creating a tag as part of the build, I need to look at your build showcasing the problem to say anything concrete as it would very much depend on what specifically you are doing.

Have tried this any other suggestions

You have extra spaces around = in Bash variable assignment, so it’s probably ineffective.

Try

env:
  - version=$(git …)