Reputation: 26904
I have the following task to achieve in our company's Jira-Bamboo-Bitbucket setup.
We want Jira to trigger Bamboo builds and assign proper version number to project.
We use Ant to perform builds.
Currently Bamboo governs project versioning thanks to variables in build plan.
In order to run my build script from Bamboo or Eclipse, I did the following
<input addproperty="project.version" message="Input current version or use arguments" />
----
<jar compress="true" destfile="build/publish/${project.name}-${project.version}.jar">
The meaning of the above lines is that I can either pass -Dproject.version=${bamboo.projectVersion}
as Ant argument or be asked by Ant which version number to build. If I run my build from Eclipse I either type the version number or use a conventional versioning for my local builds.
Now I want to move a step ahead and use Jira. I know Jira can override plan variables in Bamboo, and it has a very convenient UI for that. But my boss asked to use the built in ${jira.version}
variable in order to avoid to instruct people to override a variable.
So I thought: the idea should be either picking Jira-provided version number, or use Bamboo's configured version number, or ultimately ask user.
I ended up with the following code that works in my local Eclipse environment
<condition property="version" value="${jira.version}" if:set="jira.version">
<isset property="jira.version" />
</condition>
<condition property="version" value="${project.version}" if:set="project.version">
<isset property="project.version" />
</condition>
<input addproperty="version" message="Input current version or use arguments" />
I tried with a few combinations or run configurations and they all matched my requirements.
Eager to test in Bamboo, I edited my build script so to pass both project and Jira version
Target
"2 - jar" -Dproject.version="${bamboo.project.version}.${bamboo.buildNumber}" -Djira.version="${jira.version}" -Dbuild.number="${bamboo.buildNumber}"
Sadly, when I tried to run the plan both from stand-alone and from Jira trigger I was greeted by an angry Chuck... ahem... Bamboo that something went wrong
/usr/share/ant/bin/ant: line 336: -Djira.version=${jira.version}: bad substitution
Ant seems to accept any variable than Jira's. How can let Ant use a Jira-dictated version number? Or, more in general, Jira-dictated properties?
Upvotes: 0
Views: 292
Reputation: 26904
Seems my error in understanding Jira variable substitution
Wrong
-Djira.version="${jira.version}"
Correct
-Djira.version="${bamboo.jira.version}"
Bamboo actually puts all variables under its scope. No matter if they are injected by Jira or controlled by the project.
Another part of the solution was to define a default variable jira.version
within the build plan to avoid the bad substitution error.
It meant that if I ran the build manually from Bamboo (e.g. to test a recent commit), then -Dproject.version
will kick into version
, but if Bamboo is triggered by Jira, then, -Djira.version
will have priority
Upvotes: 1