使用Hudson从Maven到声纳的项目版本 [英] project version from maven to sonar using hudson

查看:105
本文介绍了使用Hudson从Maven到声纳的项目版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven2,hudson和声纳 在进行声纳分析时-我想通过某种方式将Hudson build#附加到项目的Maven版本

i am using maven2 , hudson and sonar while doing sonar analysis - i would like some way to append the Hudson build# to the maven version of the project

项目版本每2周更改一次-因此请在前2周中进行示例:

The project version changes every 2 weeks - so take an example in the first 2 weeks :

<version>abc-SNAPSHOT</version>

两周后,下一个版本可能类似于:

after two weeks the next version could be something like :

<version>xyz-SNAPSHOT</version>

我想要的是将build#附加到pom中已经存在的版本中-该版本已被拾取并传递给声纳

what I want is to append the build# to the version already present in pom - which is being picked up and passed to sonar

注意:

-Dsonar.projectVersion=xyz-SNAPSHOT-${BUILD_NUMBER}

在这里-我正在对版本进行硬编码,并动态传递构建版本

Here - I am hardcoding the version and dynamically passing the build#

我想要的是能够从maven中动态获取版本(无需更改),而只需动态地附加build#

what I want is to be able to dynamically pick up the version from maven ( without changing it ) and simply appending the build# dynamically

关于如何实现的任何想法? 谢谢, 讽刺

any ideas of how this can be achieved ? Thanks, satish

推荐答案

您可以使用Groovy脚本读取版本并放入环境变量: 在Jenkins中获取Maven版本

You can use Groovy script to read the version and put on environment variable: Getting Maven Version in Jenkins

我按时使用了此脚本来解析版本:

I used this script on time to parse the version:

def project = new XmlParser().parse("/pom.xml")
def artifactId =  project.artifactId.text().trim()
def version = project.version.text().trim()
println "ArtifactId: [" + artifactId + "]"
println "Version: [" + version + "]"

在附加属性"字段中设置以下内容: -Dsonar.projectVersion = $ {MAVEN_VERSION}-$ {BUILD_NUMBER}

After set "Additional properties" field with: -Dsonar.projectVersion=${MAVEN_VERSION}-${BUILD_NUMBER}

如果Jenkins没有获得该变量,请尝试安装: https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+插件

If Jenkins don't get the variable, try install: https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

这篇关于使用Hudson从Maven到声纳的项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆