Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

GitLab Deploy – Package Registry – A Complete Guide


๐Ÿ—๏ธ 1. Ensure Your GitLab Project Is Maven-Ready

To store your Java packages (JAR/WAR) into the GitLab Package Registry using GitLab CI/CD (SaaS, version 18.x), you can use GitLabโ€™s built-in Maven repository support.

Hereโ€™s a step-by-step guide to:

โœ… Build your Java project
โœ… Upload the .jar or .war to GitLabโ€™s Maven Package Registry
โœ… Do this all through your .gitlab-ci.yml pipeline

In your project root:

Ensure pom.xml (for Maven) is set up with:

<project>
  ...
  <groupId>com.example</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0.0</version>
  ...
</project>
Code language: HTML, XML (xml)

๐Ÿงช 2. GitLab Package Registry URL

GitLab SaaS Maven registry endpoint:

https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/maven
Code language: HTML, XML (xml)

You can find <PROJECT_ID> in your GitLab project settings or by using:

https://gitlab.com/<namespace>/<project_name>
Code language: HTML, XML (xml)

๐Ÿ” 3. Create a CI/CD Job to Publish Artifact

.gitlab-ci.yml example for Maven:

stages:
  - build
  - publish

variables:
  MAVEN_CLI_OPTS: "-B -DskipTests"

build-job:
  stage: build
  image: maven:3.8.7-jdk-11
  script:
    - mvn $MAVEN_CLI_OPTS clean package
  artifacts:
    paths:
      - target/*.jar
      - target/*.war

publish-job:
  stage: publish
  image: maven:3.8.7-jdk-11
  script:
    - mvn deploy -s settings.xml
  only:
    - main
Code language: PHP (php)

โš™๏ธ 4. Add settings.xml for GitLab Auth

In the root of your repo (or dynamically generate in CI):

<settings>
  <servers>
    <server>
      <id>gitlab</id>
      <username>gitlab-ci-token</username>
      <password>${env.CI_JOB_TOKEN}</password>
    </server>
  </servers>
</settings>
Code language: HTML, XML (xml)

Ensure your pom.xml contains:

<distributionManagement>
  <repository>
    <id>gitlab</id>
    <url>https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/maven</url>
  </repository>
</distributionManagement>
Code language: HTML, XML (xml)

๐Ÿ›ก๏ธ 5. Use the CI_JOB_TOKEN Securely

  • gitlab-ci-token is a special user recognized by GitLabโ€™s package registry.
  • CI_JOB_TOKEN is auto-injected in GitLab CI/CD and scoped to your project.

๐Ÿ“ฆ 6. Check Published Packages

After the pipeline completes:

  1. Go to your GitLab project
  2. Click on Packages & Registries โ†’ Package Registry
  3. Youโ€™ll see your .jar or .war listed

๐Ÿง  Bonus: Clean Up or Promote Packages

You can add manual jobs to:

  • Promote packages to another environment
  • Delete old versions via API
  • Install them in another Java project using Maven:
<dependency>
  <groupId>com.example</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0.0</version>
</dependency>
Code language: HTML, XML (xml)

โœ… Summary

StepDescription
Build ArtifactUse mvn package in CI job
Upload to GitLabUse mvn deploy with GitLab Maven repo
AuthUse CI_JOB_TOKEN with gitlab-ci-token
ViewPackages tab in GitLab UI

How to use Package registry using Gradle

Here is a step-by-step guide to publish JAR/WAR packages from a Gradle-based Java project to GitLabโ€™s Maven Package Registry, using GitLab SaaS 18.x.


โœ… Overview

  • Youโ€™ll use GitLabโ€™s Maven-compatible Package Registry
  • Youโ€™ll configure Gradle to use GitLab as a Maven repo
  • Youโ€™ll automate it using .gitlab-ci.yml and CI_JOB_TOKEN

๐Ÿ“ 1. Setup Your Gradle Project

In your build.gradle file:

plugins {
    id 'java'
    id 'maven-publish'
}

group = 'com.example'
version = '1.0.0'

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            name = "GitLab"
            url = uri("https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/maven")
            credentials {
                username = project.findProperty("gitlabUser") ?: System.getenv("CI_JOB_TOKEN")
                password = project.findProperty("gitlabToken") ?: System.getenv("CI_JOB_TOKEN")
            }
        }
    }
}
Code language: JavaScript (javascript)

Replace <PROJECT_ID> with your GitLab project ID. You can find it on the project homepage (e.g., gitlab.com/api/v4/projects/1234567).


๐Ÿ” 2. No Hardcoded Credentials

Do not store username/token in code.

In CI/CD, GitLab will inject CI_JOB_TOKEN automatically. For local testing, you can override via gradle.properties or CLI:

gitlabUser=gitlab-ci-token
gitlabToken=<your personal access token>
Code language: HTML, XML (xml)

๐Ÿงช 3. Test Locally (Optional)

./gradlew publish \
  -PgitlabUser=gitlab-ci-token \
  -PgitlabToken=<your GitLab personal access token>
Code language: HTML, XML (xml)

โš™๏ธ 4. Create .gitlab-ci.yml

stages:
  - build
  - publish

variables:
  GRADLE_USER_HOME: "$CI_PROJECT_DIR/.gradle"

build-job:
  stage: build
  image: gradle:8.2.1-jdk17
  script:
    - gradle build

publish-job:
  stage: publish
  image: gradle:8.2.1-jdk17
  script:
    - gradle publish
  only:
    - main
Code language: JavaScript (javascript)

This will publish the JAR/WAR file to GitLab Package Registry on main branch only.


๐Ÿ“ฆ 5. Where to View Packages

After successful pipeline execution:

  • Navigate to Your Project โ†’ Packages & Registries โ†’ Package Registry
  • Youโ€™ll see the .jar or .war under your published Maven group.

๐Ÿ” 6. How to Use in Other Projects

In another Gradle project, consume the published package:

repositories {
    maven {
        url = uri("https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/maven")
        credentials {
            username = 'gitlab-ci-token'
            password = System.getenv("CI_JOB_TOKEN") // or use .env or gradle.properties
        }
    }
}

dependencies {
    implementation 'com.example:your-artifact:1.0.0'
}
Code language: JavaScript (javascript)

โœ… Summary Table

StepAction
build.gradleAdd maven-publish, configure GitLab Maven repo
CredentialsUse CI_JOB_TOKEN with gitlab-ci-token
.gitlab-ci.ymlRun gradle publish from CI/CD
Registry URLhttps://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/maven
View PackagesProject โ†’ Packages & Registries โ†’ Package Registry

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored…

Read More

Best Tools for Software Composition Analysis (SCA)

Hereโ€™s a clear and professional explanation of the three related concepts you asked about โ€” all of which are critical parts of secure software development, especially in…

Read More

Top 10 AI Code Review Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI code review tools have become essential for developers aiming to enhance code quality, streamline workflows, and accelerate software delivery. These tools leverage advanced…

Read More

Top 10 Expense Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction Expense management tools are critical for businesses of all sizes in 2026 as they help streamline financial processes, improve budgeting, ensure compliance, and enhance financial visibility….

Read More

Top 10 Web Application Firewall (WAF) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In the rapidly evolving landscape of cybersecurity, Web Application Firewalls (WAFs) have become a critical component in defending web applications from malicious attacks such as SQL…

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devicesโ€”laptops, desktops, mobile devices, and other endpointsโ€”that connect to their networks. With the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x