简体   繁体   English

在Ant Bamboo构建中使用Jira或默认项目版本

[英]Using Jira or default project version in Ant Bamboo build

I have the following task to achieve in our company's Jira-Bamboo-Bitbucket setup. 在我们公司的Jira-Bamboo-Bitbucket设置中,我要完成以下任务。

We want Jira to trigger Bamboo builds and assign proper version number to project. 我们希望Jira触发Bamboo版本并为项目分配适当的版本号。

We use Ant to perform builds. 我们使用Ant来执行构建。

Currently Bamboo governs project versioning thanks to variables in build plan. 当前,由于构建计划中的变量,Bamboo管理项目版本控制。

In order to run my build script from Bamboo or Eclipse, I did the following 为了从Bamboo或Eclipse运行构建脚本,我做了以下工作

<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. 上面-Dproject.version=${bamboo.projectVersion}行的意思是,我可以将-Dproject.version=${bamboo.projectVersion}作为Ant参数传递,或者由Ant询问要构建哪个版本号。 If I run my build from Eclipse I either type the version number or use a conventional versioning for my local builds. 如果我从Eclipse运行构建,则可以输入版本号或对本地构建使用常规版本控制。

Now I want to move a step ahead and use Jira. 现在,我想向前迈一步,使用Jira。 I know Jira can override plan variables in Bamboo, and it has a very convenient UI for that. 我知道 Jira可以在Bamboo中覆盖计划变量,并且为此提供了非常方便的UI。 But my boss asked to use the built in ${jira.version} variable in order to avoid to instruct people to override a variable. 但是我的老板要求使用内置的${jira.version}变量,以避免指示人们覆盖变量。

So I thought: the idea should be either picking Jira-provided version number, or use Bamboo's configured version number, or ultimately ask user. 所以我想:这个主意应该是选择Jira提供的版本号,或者使用Bamboo的配置版本号,或者最终询问用户。

I ended up with the following code that works in my local Eclipse environment 我最终得到了在我的本地Eclipse环境中可以运行的以下代码

    <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 渴望在Bamboo中进行测试,因此我编辑了构建脚本,以便同时传递项目和Jira版本

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 可悲的是,当我尝试从独立运行和从吉拉触发器运行该计划时,都被愤怒的查克(Chuck )招呼了...嗯...竹子说出了问题

/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? 如何让Ant使用Jira规定的版本号? Or, more in general, Jira-dictated properties? 或更笼统地说,是吉拉(Jira)规定的属性?

Seems my error in understanding Jira variable substitution 在理解Jira变量替换时似乎出现了我的错误

Wrong 错误

-Djira.version="${jira.version}"

Correct 正确

-Djira.version="${bamboo.jira.version}"

Bamboo actually puts all variables under its scope. Bamboo实际上将所有变量置于其范围内。 No matter if they are injected by Jira or controlled by the project. 无论是由Jira注入还是由项目控制。

Another part of the solution was to define a default variable jira.version within the build plan to avoid the bad substitution error. 解决方案的另一部分是在构建计划中定义默认变量jira.version以避免错误的替换错误。

It meant that if I ran the build manually from Bamboo (eg 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 这意味着,如果我从Bamboo手动运行构建(例如,测试最近的提交),则-Dproject.version将插入version ,但如果Bamboo由Jira触发,则-Djira.version将具有优先级

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM