Я использую Gitlab-ci с docker в качестве исполнителя для создания своего проекта maven.
Я использую buildnumber-maven-plugin v1.4 для получения git информации, подобной этой:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath />
</parent>
<groupId>com.xxxxxx</groupId>
<artifactId>xxxxxx</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<!-- ********************************************************** -->
<!-- PROPERTIES -->
<!-- ********************************************************** -->
<properties>
<revision>0.1.0-SNAPSHOT</revision>
<xxxxxx.boilerplate.version>0.5.2-SNAPSHOT</xxxxxxxx.boilerplate.version>
<spring.framework.versoin>2.2.1.RELEASE</spring.framework.versoin>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<!-- ********************************************************** -->
<!-- MODULES -->
<!-- ********************************************************** -->
<modules>
<module>client-ui</module>
<module>application</module>
<module>domain</module>
<module>infrastructure</module>
</modules>
<!-- ********************************************************** -->
<!-- REPOSITORIES -->
<!-- ********************************************************** -->
<repositories>
<repository>
<id>java-boilerplate-maven-bucket-release</id>
<name>xxxxxx Java BoilerPlate</name>
<url>s3://xxxxxxxxxx/release</url>
</repository>
<repository>
<id>java-boilerplate-maven-bucket-snapshot</id>
<name>xxxxxx Java BoilerPlate</name>
<url>s3://xxxxxxxxxx/snapshot</url>
</repository>
</repositories>
<!-- ********************************************************** -->
<!-- DEPENDENCIES MANAGEMENT -->
<!-- ********************************************************** -->
<dependencyManagement>
<!-- xxxxxxx JAVA BOILERPLATE -->
<dependencies>
<dependency>
<groupId>com.xxxxxxx</groupId>
<artifactId>infrastructure</artifactId>
<version>${xxxxxx.boilerplate.version}</version>
</dependency>
<dependency>
<groupId>com.xxxxxxxx</groupId>
<artifactId>domain</artifactId>
<version>${xxxxxx.boilerplate.version}</version>
</dependency>
<dependency>
<groupId>com.xxxxxxx</groupId>
<artifactId>security</artifactId>
<version>${xxxxxxx.boilerplate.version}</version>
</dependency>
<!-- SPRING BOOT WEB STARTER -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.framework.versoin}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data</artifactId>
<version>${spring.framework.versoin}</version>
</dependency>
<!-- SPRING BOOT TEST STARTER -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.framework.versoin}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- ********************************************************** -->
<!-- DEPENDENCIES -->
<!-- ********************************************************** -->
<dependencies>
</dependencies>
<!-- ********************************************************** -->
<!-- VERSIONING -->
<!-- ********************************************************** -->
<scm>
<developerConnection>scm:git:ssh://git@xxx.Xxxx.XXX.XXX:xxxx/xxxxxx.git</developerConnection>
</scm>
<!-- ********************************************************** -->
<!-- BUILD -->
<!-- ********************************************************** -->
<build>
<!-- FILE NAME -->
<finalName>${project.artifactId}-${project.version}-${buildNumber}</finalName>
<!-- PLUGINS -->
<plugins>
<!-- delete nodjs build folders on maven clean -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>node/**</include>
<include>client-ui/dist/**</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- mojo buildnumer maven plugin -->
<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>
<shortRevisionLength>8</shortRevisionLength>
<scmBranchPropertyName>true</scmBranchPropertyName>
<scmBranchPropertyName>scmBranch</scmBranchPropertyName>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<!-- maven jar plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
<Build-Branch>${scmBranch}</Build-Branch>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- maven antrun plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>echo-properties</id>
<goals>
<goal>run</goal>
</goals>
<phase>validate</phase>
<configuration>
<target>
<echo message="buildnumber-maven-plugin properties:"/>
<echo message=" $${scmBranch}: ${scmBranch}" />
<echo message=" $${buildNumber}: ${buildNumber}" />
<echo message=" $${timestamp}: ${timestamp}" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<!-- EXTENSIONS -->
<extensions>
<!-- Amazon aws repository s3 pulgin -->
<extension>
<groupId>com.allogy.maven.wagon</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.0</version>
</extension>
</extensions>
</build>
Проблема в том, что когда я строю свой проект на локальном компьютере, maven получает всю git информацию, как ожидается, но когда сборка выполняется на gitlab, она не может получить имя ветви scm, и я получаю это предупреждение:
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ securteck ---
[INFO] Deleting /builds/securteck/securteck (includes = [node/**, client-ui/dist/**], excludes = [])
[INFO]
[INFO] --- buildnumber-maven-plugin:1.4:create (default) @ securteck ---
[INFO] ShortRevision tag detected. The value is '8'.
[INFO] Executing: /bin/sh -c cd '/builds/securteck/securteck' && 'git' 'rev-parse' '--verify' '--short=8' 'HEAD'
[INFO] Working directory: /builds/securteck/securteck
[INFO] Storing buildNumber: efd0a966 at timestamp: 1586711200134
[WARNING] Cannot get the branch information from the git repository:
Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref
[INFO] ShortRevision tag detected. The value is '8'.
[INFO] Executing: /bin/sh -c cd '/builds/securteck/securteck' && 'git' 'rev-parse' '--verify' '--short=8' 'HEAD'
[INFO] Working directory: /builds/securteck/securteck
[INFO] Storing buildScmBranch: UNKNOWN
Я использую одну и ту же версию maven как на локальном, так и на gitlab runner.
Есть мой контент gitlab-ci.yml:
image: maven:latest
# Services goes here
services:
- docker:dind
# Cache goes here
cache:
paths:
- .m2/repository
- frontend-app/node_modules/
# ENV variables goes here
# Before script goes here
# Stages definition goes here
stages:
- build
# Build stage
build:
stage: build
before_script:
- yum install -y git
- git --version
- mvn --version
script:
- echo "****** start scripts of build stage ******"
- mvn clean install --settings .ci/settings.xml --no-transfer-progress
Есть идеи?