9
我有一個JSF,Spring,Hibernate項目。 在頁面的底部,我必須有版本號。 使用jenkins(哈德森)我已經安裝了「參數化版本」。但它似乎不起作用。我如何獲得jenkins內部版本號,maven項目版本,svn修訂版號並將其顯示在我的JSF頁面上?如何獲得jenkins內部版本號,svn修訂版號......並將其顯示在我的JSF頁面上?
我在網上找不到有用的例子。
由於
主/資源/ COM /示例/ build.properties
custom_version = Test 1.0
pom_version = ${pom_version}
svn_revision = ${svn_revision}
build_tag = ${build_tag}
build_number = ${build_number}
build_id = ${build_id}
faces-config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<resource-bundle>
<base-name>com.example.build</base-name>
<var>build</var>
</resource-bundle>
</application>
</faces-config>
version.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
>
<center>
<p>Version: #{build['custom_version']}.#{build['build_tag']}.#{build['build_number']}.#{build['build_id']}.#{build['svn_revision']}</p>
</center>
</ui:composition>
H ERE是我工作的解決方案:
主/資源/ COM /例子/ build.properties
custom_version = ${env.CUSTOM_VERSION}
custom_message = ${env.CUSTOM_MESSAGE}
pom_version = ${pom.version}
pom_name = ${pom.name}
pom_description = ${pom.description}
svn_revision = ${env.SVN_REVISION}
build_tag = ${env.JOB_NAME}
build_number = ${env.BUILD_NUMBER}
build_id = ${env.BUILD_ID}
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>jenkins_build_deploy</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<name>jenkins_build_deploy</name>
<description>jenkins_build_deploy application</description>
<url>http://example.com/jenkins_build_deploy</url>
<scm>
<url>http://127.0.0.1/dummy</url>
<connection>scm:svn:http://127.0.0.1/dummy</connection>
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
<tag>HEAD</tag>
</scm>
<build>
<finalName>jenkins_build_deploy</finalName>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
<webappDirectory>${project.build.directory}/${project.artifactId}</webappDirectory>
<warName>${project.artifactId}</warName>
<webResources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<directory>${project.build.directory}</directory>
<directory>${project.build.sourceDirectory}</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>gif</nonFilteredFileExtension>
<nonFilteredFileExtension>ico</nonFilteredFileExtension>
<nonFilteredFileExtension>jpg</nonFilteredFileExtension>
<nonFilteredFileExtension>png</nonFilteredFileExtension>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>jasper</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<directory>${project.build.directory}</directory>
<directory>${project.build.sourceDirectory}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<debug>true</debug>
<echo>true</echo>
<terse>true</terse>
<force>true</force>
<!-- <autoCreate>true</autoCreate> -->
<!-- <skip>${test.int.skip}</skip> -->
<glassfishDirectory>${glassfish.glassfishDirectory}</glassfishDirectory>
<user>${glassfish.user}</user>
<adminPassword>${glassfish.adminPassword}</adminPassword>
<!-- <passwordFile>${glassfish.home}/domains/${project.artifactId}/master-password</passwordFile> -->
<domain>
<name>${glassfish.domain.name}</name>
<host>${glassfish.domain.host}</host>
<adminPort>${glassfish.domain.adminPort}</adminPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/${project.artifactId}.war</artifact>
</component>
</components>
</configuration>
<executions>
<execution>
<goals>
<goal>redeploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>buildnumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
****
</dependency>
</dependencies>
</project>
詹金斯/ config.xml中
<?xml version='1.0' encoding='UTF-8'?>
<maven2-moduleset plugin="[email protected]">
<actions/>
<description>jenkins_build_deploy</description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>CUSTOM_VERSION</name>
<description>custom_version = Test 1.0 ${env.CUSTOM_VERSION}</description>
<defaultValue>1.0.1</defaultValue>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>CUSTOM_MESSAGE</name>
<description>Test Env.</description>
<defaultValue>Test Env.</defaultValue>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.SubversionSCM" plugin="[email protected]">
<locations>
<hudson.scm.SubversionSCM_-ModuleLocation>
<remote>http://example.com/svn/jenkins_build_deploy/trunk</remote>
<local>.</local>
<depthOption>infinity</depthOption>
<ignoreExternalsOption>false</ignoreExternalsOption>
</hudson.scm.SubversionSCM_-ModuleLocation>
</locations>
<excludedRegions/>
<includedRegions/>
<excludedUsers/>
<excludedRevprop/>
<excludedCommitMessages/>
<workspaceUpdater class="hudson.scm.subversion.UpdateUpdater"/>
<ignoreDirPropChanges>false</ignoreDirPropChanges>
<filterChangelog>false</filterChangelog>
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class="vector"/>
<concurrentBuild>false</concurrentBuild>
<rootModule>
<groupId>com.example</groupId>
<artifactId>jenkins_build_deploy</artifactId>
</rootModule>
<goals>clean install -Dmaven.test.skip=true glassfish:deploy</goals>
<aggregatorStyleBuild>true</aggregatorStyleBuild>
<incrementalBuild>false</incrementalBuild>
<perModuleEmail>true</perModuleEmail>
<ignoreUpstremChanges>false</ignoreUpstremChanges>
<archivingDisabled>false</archivingDisabled>
<resolveDependencies>false</resolveDependencies>
<processPlugins>false</processPlugins>
<mavenValidationLevel>-1</mavenValidationLevel>
<runHeadless>false</runHeadless>
<disableTriggerDownstreamProjects>false</disableTriggerDownstreamProjects>
<settings class="jenkins.mvn.DefaultSettingsProvider"/>
<globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
<reporters/>
<publishers/>
<buildWrappers/>
<prebuilders>
<hudson.tasks.Shell>
<command>echo CUSTOM_VERSION: $CUSTOM_VERSION
echo CUSTOM_MESSAGE: $CUSTOM_MESSAGE</command>
</hudson.tasks.Shell>
</prebuilders>
<postbuilders/>
<runPostStepsIfResult>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
</runPostStepsIfResult>
</maven2-moduleset>
謝謝。 我在$ {basedir}/src/main/resources中有* .jasper文件我得到 org.apache.catalina.LifecycleException:java.io.StreamCorruptedException:無效的流標頭:EFBFBDEF。有關更多詳細信息,請參閱server.log。 – ahmet 2013-02-20 16:15:09
您還需要包括 ''' http://127.0.0.1/dummy '' SCM :SVN:HTTP://127.0.0.1/dummy '' SCM:SVN :https://127.0.0.1/dummy developerConnection>' ' HEAD ' ' ' –
ahmet
2013-02-20 16:16:10
嗯,當然,您確實需要有' '部分。 –
carlspring
2013-02-20 16:22:27