将 buld 和提交哈希添加到清单

mma*_*ran 3 java git maven jenkins

我正在尝试将 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>
Run Code Online (Sandbox Code Playgroud)

但是当我构建它时,我得到的只是:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jenkins
Build-Jdk: 1.8.0_74
Run Code Online (Sandbox Code Playgroud)

我的构建参数是:

clean install -Dbuild.number=${BUILD_NUMBER} -Dbuild.revision=${GIT_COMMIT}
Run Code Online (Sandbox Code Playgroud)

但是在日志中,我没有看到正在调用的程序集插件,我看到了 clean、compile、resources、jar 和 install。但没有组装。

我需要做什么特别的事情来运行这个插件吗?还是我做错了,我完全需要别的东西?

Ond*_*žka 5

对于 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
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)