DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • Streamlining AWS Lambda Deployments
  • Source Code Management and Branching Strategies for CI/CD
  • Pipeline as a Service: How To Test Pipelines in GitLab
  • Unraveling the Siloing Issue When Using Argo CD With Other Similar Tools

Trending

  • Securing Cloud Storage Access: Approach to Limiting Document Access Attempts
  • Secure Your API With JWT: Kong OpenID Connect
  • Maximizing Developer Efficiency and Productivity in 2024: A Personal Toolkit
  • Exploring the Frontiers of AI: The Emergence of LLM-4 Architectures
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using Git Submodules With Gitlab CI/CD

Using Git Submodules With Gitlab CI/CD

We use Git submodules to keep a Git repository as a subdirectory of another Git repo. This is usually done for a set of common files you want to refer to in multiple repos.

By 
Rishab Aggarwal user avatar
Rishab Aggarwal
·
Apr. 18, 21 · Tutorial
Like (5)
Save
Tweet
Share
26.2K Views

Join the DZone community and get the full member experience.

Join For Free

We use Git submodules to keep a Git repository as a subdirectory of another Git repository.  This is usually done when you have a set of common files you want to refer to in multiple repos.

In my personal experience, I found git submodules especially useful when working with Terraform.

Configure the .gitmodules File

When you use Git submodules, your project should have a file named .gitmodules. 

To create .gitmodules, you need to use the git submodule command. There are two ways you can use it:

  • If the repo you want to use as a submodule exists on a relative path, i.e., on the same GitLab server, then use the following command:
Textile
 




x


 
1
$ git submodule add ../chaconinc/project-y.git
2
Cloning into 'project-y'...
3
remote: Counting objects: 11, done.
4
remote: Compressing objects: 100% (10/10), done.
5
remote: Total 11 (delta 0), reused 11 (delta 0)
6
Unpacking objects: 100% (11/11), done.
7
Checking connectivity... done.



  • For submodules not located on the same GitLab server, use the full URL:  
Textile
 




xxxxxxxxxx
1


 
1
$ git submodule add https://gitserver.com/group/project-y.git
2
Cloning into 'project-y'...
3
remote: Counting objects: 11, done.
4
remote: Compressing objects: 100% (10/10), done.
5
remote: Total 11 (delta 0), reused 11 (delta 0)
6
Unpacking objects: 100% (11/11), done.
7
Checking connectivity... done.



Both the above commands should be executed from within the project in which you want to use 'project-y' as a submodule.

Updating gitlab-ci.yml, Use Git Submodules in CI/CD Jobs

To make submodules work correctly in CI/CD jobs:

  1. Make sure you use relative URLs for submodules located in the same GitLab server.
  2. You can set the GIT_SUBMODULE_STRATEGY variable to either normal or recursive.

In the variables section of your gitlab-ci file, add the following:

Textile
 




xxxxxxxxxx
1


 
1
variables:
2
  GIT_SUBMODULE_STRATEGY: recursive 



We used the recursive option so that all folders inside submodules are checked out. 

Next, in the default section of our gitlab-ci file, we had to add the following to make sure the latest version of submodules is checked out on every execution:

Adding tags, setting 'sslVerify' is optional, but we had to add submodule init and update with --recursive --remote to make sure submodules work properly.

Textile
 




x


 
1
default:
2
  tags:
3
    - <your runner Name>
4
  before_script:
5
    - git config --global http.sslVerify "false"
6
    - git submodule init
7
    - git submodule update --recursive --remote



Once the above lines were added, submodules for us worked seamlessly in GitLab.

Continuous Integration/Deployment Git GitLab

Opinions expressed by DZone contributors are their own.

Related

  • Streamlining AWS Lambda Deployments
  • Source Code Management and Branching Strategies for CI/CD
  • Pipeline as a Service: How To Test Pipelines in GitLab
  • Unraveling the Siloing Issue When Using Argo CD With Other Similar Tools

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: