My CI/CD doesn't push Docker images on my Gitlab registry

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 :slight_smile:

Damien

Hi @DamDGN

I am no expert in docker-maven-plugin, but aren’t you missing goal push in your pom.xml?

I think -DpushImage might imply that the build job also pushes the image, but beyond that I’m also confused about how this happens!

Hi @balonik

I’ve try to add that but it’s the same but it was a good idea :wink:

<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>
										<goal>push</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/<gitlab username>/<project name>/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>```