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

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

问题描述

我正在使用 maven2 、 hudson 和 sonar在进行声纳分析时 - 我想要某种方式将 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 到 sonar 的项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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