How can I retrieve ant property into teamcity - maven

I am configuring teamcity project for ant. I know I can retrieve maven build number from pom.xml using ${maven.build.number} into teamcity. I am not getting how to retrieve the same from ant xml. I have configured a property in ant file for version.
<project xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<property name="version" value="1.0.0.16"/>

Teamcity provides a large number of properties that are automatically made available to your ANT build (via System properties). In your specific case the Teamcity build number is available as:
<property name="version" value="${build.number}"/>
There are dozens of other properties you can make available as well, consult the Teamcity Docs

Related

Automatically derive mandatory SonarQube properties from pom file in Jenkins

Situation:
I want to analyze my project with SonarQube (5.4) triggered by Jenkins (1.642.4). It is a java project build with maven.
I see two ways to trigger the analysis:
Post Build Action "SonarQube analysis with maven" but it's deprecated, so I don't want to use it
Post Build Step "Execute SonarQube Scanner", is the recommended way.
Problem:
If I use the deprecated Post Build Action, the properties for sonar project configuration are derived automatically from the project pom.
It I use the recommended Post Build Step, I receive the Exception
You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
Undesired Solution:
The solution is to provide the required properties, via sonar-project.properties file in the java project or via parameters in Jenkins step.
IMHO: this is duplication. All relevant information is defined in the Maven pom: projectKey can be derived from artifactId, projectName and projectVerstion are same properties in maven. Especially the projectVersion is critical. I don't want to update the project version after each release (or write some code in release plugin to update it automatically).
What I want
I want to use the recommended Post Build Step in Jenkins, without redefine all project properties for all my project to make sonar happy. Instead sonar/jenkins/plugin/whatever should derive the properties from my maven pom file. Is there an additional plugin I can use? Can I reconfigure my Jenkins-Sonar-Plugin?
I don't want to provide any sonar specific information in my pom/project, because the project shouldn't care about sonar. It should contain only information required to build the project.
The documentation (although slightly confusing, see edit below) explains how to use a generic post-build step (leveraging environment variables), instead of the deprecated post-build action. in short:
install latest SonarQube Plugin (v2.4 as of now) in Jenkins
in System Config under SonarQube servers: check Enable injection of SonarQube server configuration as build environment variables
in the configuration of your Maven project:
check Prepare SonarQube Scanner environment
add a post-build step Invoke top-level Maven targets and leverage the injected environment variables in the Goals field e.g.:
$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_AUTH_TOKEN
Edit: when the documentation says The Post-build Action for Maven analysis is deprecated. , it refers to the old post-build action which is not documented anymore. The paragraph after that warning (summarized in this answer) really is the recommended procedure. Illustration here if it's still not clear.
Using SonarQube Scanner as a post build step you can configure it with at least this properties in Analysis properties:
sonar.projectKey=${POM_ARTIFACTID}
sonar.projectName=${POM_DISPLAYNAME}
sonar.projectVersion=${POM_VERSION}
sonar.sources=src
sonar.java.binaries=target
sonar.language=java
sonar.sourceEncoding=UTF-8
POM_* variables are mapped by Jenkins from Maven GAV info, look here: https://github.com/jenkinsci/jenkins/pull/933/files

Integrating JMeter as part of Maven project

I'm starting my work on the project related to creating some custom set of jmeter components that would be bundled in my custom jmeter distribution.
Those custom components are part of the Maven project and what I would like to do is try to integrate this maven project with latest jmeter project to be able to build and deliver jmeter build that contains my custom set of components with all related dependency jars.
Problem is that jmeter project is ant project.
I've came across this: http://maven.apache.org/guides/mini/guide-using-ant.html, maven-antrun-plugin which gives a possibility to embed ant task inside the maven pom.
Since I've never worked with ant (only worked with maven), my idea of using this plugin inside pom would be to define following targets:
download jmeter source from svn repository
build jmeter distribution
after building maven project (after install phase), copy jars (component and dependency jars) to the jmeter lib to form the final jmeter distribution with my custom components.
My question is: Do you find this approach as the right one (are there some things to consider while doing this) and if not, can you suggest me some other ways of achieving the same goal?
Thanks in advance
Since JMeter 2.6, Apache JMeter artifacts are published on maven2 repositories.
See:
http://mvnrepository.com/artifact/org.apache.jmeter/
See for an example :
https://github.com/Ronnie76er/jmeter-maven-plugin/wiki
So what you can do is have your maven project that references these artifacts as dependencies.
And if you want to generate a full bundle containing JMETER+You Plugins then use AntRunner to :
Unzip the official distribution
Copy your artifact in jmeter/lib/ext and dependencies in jmeter/lib
rezip it

Jenkins JDepend Plugin reports JAR classes

I am using 1.467 and Jenkins JDepend plugin 1.2.3.
When I build, it generates the JDepend report.
No problem.
THe problem is that I get reports on classes like:
org.apache.commons.fileupload
org.hibernate.ejb
Packages report on classes that I didn't write.
How I configure this so that it JDepend only run on classes that I write?
com.mycompany.myproject
for example.
Thanks.
JDepend Maven Plugin looks quite old and seems to be in beta. It does not support a way to exclude packages/classes. I assume jenkins JDepend Plugin uses the information from this to generate the report.
JDepend itself provides options to include/exclude classes/packages from analysis. JDepend ant task provides support for this as well.
One possibility would be to use jdepend ant task using maven antrun plugin (or directly invoke jdepend using maven exec plugin) to do the analysis and specify the report file to jenkins plugin for reporting.
i got it to work by setting the goal to "jdepend:generate" and setting the Pre-generated JDepend file to "target/jdepend-report.xml"

is it possible to do a Maven build using Build Forge?

Is it possible to do a Maven build using Build Forge? Currently we use Build Forge, ClearCase and ClearQuest with Ant scripts; would like to try a Maven build. Not sure if I can I have no test environment so don't want to mess up any thing and still learning all this stuff too
Maven can be invoked from any build automation framework.
Create a buildforge step that invokes your Maven build as follows:
mvn -s /path/to/maven/settings/files/mysettings.xml clean package
Explicitly selecting the settings file is recommended as this enables you customise the Maven configuration for each project.
Project isolation can be further enhanced by ensuring that each project has it's own local repository location (See the "localRepository" parameter in the settings file documentation)

How to integrate maven with cruise control?

Would like to know how to integarate cruise control with maven?
Cruise Control comes with ant integraation by default and in the config.xml has antbootstapper.But dint find any bootstrapper for maven.Would like to know the configuration for maven.
You should be able to configure maven with cruisecontrol without a need for a specific maven bootstrapper.
What you need is a bootstrapper for the version control that you are using. Cruisecontrol provides bootstrappers for most of them. Using this, you can update pom.xml.
Using the maven scm plugin, you can specify the scm configuration in your pom.xml and thereafter run mvn scm:update prior to your build. e.g.
mvn scm:update clean install

Resources