我正在尝试将jenkins内部版本号,git commit hash等添加到MANIFEST.MF文件中。我正在学习本教程:http://akeffalas.github.io/blog/2014/04/jenkins-build-info-maven-artifacts.html
这是我的POM的构建部分:
<build>
<finalName>common</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
<manifestSections>
<manifestSection>
<name>${build.manifest.section}</name>
<manifestEntries>
<Implementation-Title>com.mycompany.stuff</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Build-Number>${build.number}</Implementation-Build-Number>
<Implementation-SCM-Revision>${build.revision}</Implementation-SCM-Revision>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
</plugins>
</build>
但是当我建立它时,我得到的只是:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jenkins
Build-Jdk: 1.8.0_74
我的构建工具是:
clean install -Dbuild.number=${BUILD_NUMBER} -Dbuild.revision=${GIT_COMMIT}
但是在日志中,我没有看到调用程序集插件,我看到干净,编译,资源,jar和安装。但没有集会。
为了让这个插件运行,我需要做些什么特别的事吗?或者我完全错了,我还需要其他的东西吗?
答案 0 :(得分:1)
对于Git,您可以自动完成此操作。
要获取此信息:
Manifest-Version: 1.0
Built-By: ondra
Build-Time: 2018-10-24T15:04:25Z
Created-By: Apache Maven 3.5.0
Build-Jdk: 1.8.0_181
Main-Class: ch.zizka.myapp.MyMainClass
Name: Versions
Implementation-SCM-Revision: 85e0e665
Implementation-Version: 18.22.1-SNAPSHOT
Implementation-SCM-Branch: feature/gitCommitToManifest
在pom.xml
中使用它:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals><goal>create</goal></goals>
</execution>
</executions>
<configuration>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<shortRevisionLength>8</shortRevisionLength>
<attach>true</attach>
<addOutputDirectoryToResources>true</addOutputDirectoryToResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
<manifestSections>
<manifestSection>
<name>Versions</name>
<manifestEntries>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-SCM-Revision>${buildNumber}</Implementation-SCM-Revision>
<Implementation-SCM-Branch>${scmBranch}</Implementation-SCM-Branch>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>