%maven.project.version% is '???' when read in build step

I am trying to set the buildNumber by modifying the project version in a Bash "custom script" as a "command line" build step. This is the first build step and the script starts off like this

#!/bin/bash
 
mvn_version=%maven.project.version%
echo "version is $mvn_version" #this prints out '???'
 
suffix="%build.counter%-SNAPSHOT"
echo "suffix is $suffix" #this prints out '40-SNAPSHOT'
new_version=${mvn_version/SNAPSHOT/$suffix}

echo "new build number is $new_version" #this prints out '???'
echo "##teamcity[buildNumber '$new_version']"

 

What do I need to do so %maven.project.version% is populated and not "???"?!

5 comments

Hi Kareem,

How do you define %maven.project.version% parameter in the build configuration? Please check the parameter value on build > Parameters page. 

0

This is a TeamCity-owned parameter I do not set it. But when my first build step is of type Maven I can see in the log that the buildNumber is set first

 

[16:05:24]Skip checking for changes - changes are already collected
[16:05:24]Swabra
[16:05:24]Clearing temporary directory: /app/localstorage/tc/agent-ethan_hunt/temp/buildTmp
[16:05:24]Publishing internal artifacts
[16:05:24]Checkout directory: /app/localstorage/tc/agent-ethan_hunt/work/9a3b9b59cc050f53
[16:05:24]Updating sources: agent side checkout (3s)
[16:05:28]Swabra
[16:05:28]Step 1/4: Set Version (Maven) (3s)
[16:05:28][Step 1/4] ##teamcity[buildNumber '1.1.0-42-SNAPSHOT']
[16:05:28][Step 1/4] Initial M2_HOME = /sbcimp/run/pd/maven/3.3.3
[16:05:28][Step 1/4] Current M2_HOME = /sbcimp/run/pd/maven/3.3.3
 
As you can see "##teamcity[buildNumber '1.1.0-42-SNAPSHOT']" is being set by Teamcity here.
 
In the "General Seetings" page I have
 
Build Number Format: %maven.project.version%-%build.counter%-SNAPSHOT
 
Again I am just getting %maven.project.version% from Teamcity and not setting it myself.
0

The %maven.project.version% parameter is reported when Maven build step is running. Do you have Maven build step before running your bash script?

0

We're encountering this same issue -- there is a Maven step running a step before the command script that is attempting to echo %maven.project.version%.  It writes out ???

0

Actually, disregard - the pom file path was missing /pom.xml -- TeamCity still found the pom file but did not read it as if it was given the full file path.

0

Please sign in to leave a comment.