Jenkins Git插件使用Git commit SHA1 id设置GIT_COMMIT
环境变量,长度为40个字符。因为我想使用Git commit id作为我的版本字符串的一部分,我需要将它缩短为6个字符(例如1.0.0-d5e8dc)。 Maven捕获GIT_COMMIT
环境变量,我不知何故应该在Maven中缩短它。
答案 0 :(得分:0)
build-helper-maven-plugin
为我工作:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<!--
This property will have short Git commit id.
-->
<name>short-git-commit-id</name>
<!--
Jenkins Git Plugin sets GIT_COMMIT environment
variable which is 40 characters long SHA1 value.
-->
<value>${GIT_COMMIT}</value>
<!--
To get the first 6 characters of Git commit id, we
cut last 40-6=34 characters off.
-->
<regex>.{34}$</regex>
<replacement></replacement>
<failIfNoMatch>true</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>