Hello everyone,
I’m newbie on Gitlab CI/CD, currently I try to build a CI/CD with Gitlab but the pushImage doesn’t works. When I made a git push pipeline is correctly triggered and Build and Package jobs seems to be ok but when I’m going on containers registry (gitlab) I haven’t any image pushed.
My .gitlab-ci.yml file
stages:
- build
- package
cache:
paths:
- .m2/repository
key: "$CI_JOB_NAME"
build_job:
stage: build
script:
- apk add --no-cache maven
- mvn compile
-Dhttps.protocols=TLSv1.2
-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
-Dorg.slf4j.simpleLogger.showDateTime=true
-Djava.awt.headless=true
--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true
image: openjdk:17-alpine
package_job:
stage: package
services:
- docker:stable-dind
variables:
DOCKER_HOST: tcp://docker:2375
script:
- apk add --no-cache maven docker
- echo $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- mvn install -PbuildDocker -DskipTests=true -DpushImage
-Dhttps.protocols=TLSv1.2
-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
-Dorg.slf4j.simpleLogger.showDateTime=true
-Djava.awt.headless=true
--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true
image: openjdk:17-alpine
Here part of my pom.xml
<profiles>
<profile>
<id>buildDocker</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>${env.CI_REGISTRY_IMAGE}/${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${docker.image.dockerfile.dir}</dockerDirectory>
<serverId>gitlab</serverId>
<registryUrl>https://gitlab.com/xxxxxxxxxxxxx/xxxxxxxxxxx/container_registry</registryUrl>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<buildArgs>
<ARTIFACT_NAME>${project.build.finalName}</ARTIFACT_NAME>
<EXPOSED_PORT>${docker.image.exposed.port}</EXPOSED_PORT>
<DOCKERIZE_VERSION>${docker.image.dockerize.version}</DOCKERIZE_VERSION>
</buildArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
Thanks in advance for your help
Damien