{"id":12672,"date":"2024-12-17T11:03:32","date_gmt":"2024-12-17T11:03:32","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=12672"},"modified":"2024-12-18T08:14:36","modified_gmt":"2024-12-18T08:14:36","slug":"deploy-code-from-gitlab-to-server-using-gitlab-ci-cd","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/","title":{"rendered":"Deploy code from GitLab to Server using Gitlab CI\/CD"},"content":{"rendered":"\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">In this article, We\u2019ll learn how to set CI\/CD (<strong>Gitlab CI\/CD<\/strong>) between the Gitlab and the<strong> <\/strong>server. You can configure the pipeline to deploy your code on the specific path of the server using Runner<strong>.<\/strong><\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to GitLab<\/h2>\n\n\n\n<p>It&nbsp;is an <strong>open-source<\/strong> collaboration platform that provides powerful features beyond hosting a code repository.<\/p>\n\n\n\n<p>You can track issues, host packages, and registries, maintain Wikis, and set up <a href=\"https:\/\/cloudkul.com\/blog\/continuous-integration-continuous-delivery-and-continuous-deployment\/\"><strong>continuous integration<\/strong><\/a> (CI), <a href=\"https:\/\/cloudkul.com\/blog\/continuous-integration-continuous-delivery-and-continuous-deployment\/\"><strong>continuous deployment<\/strong> <\/a>(CD), and <strong>pipelines<\/strong>.<\/p>\n\n\n\n<p>A runner is an application that works with<em> <\/em><strong>GitLab CI\/CD<\/strong> to run the job in a pipeline. It is open-source and written in the &#8216;Go&#8217; Language. <\/p>\n\n\n\n<p>You can install <a href=\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\"><strong>GitLab runner<\/strong><\/a> on different supported operating systems.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/Untitled-Diagram.drawio-10.png\"><img loading=\"lazy\" decoding=\"async\" width=\"841\" height=\"431\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/Untitled-Diagram.drawio-10.png\" alt=\"gitlab\" class=\"wp-image-13295\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">GitLab <strong>CI\/CD concepts<\/strong><\/h2>\n\n\n\n<p>It is a method to frequently deliver\u00a0apps\u00a0to customers by introducing <a href=\"https:\/\/cloudkul.com\/blog\/jenkins-an-opensource-automation-server\/\"><strong>automation<\/strong><\/a>\u00a0into the stages of app development. %MCEPASTEBIN%<\/p>\n\n\n\n<p>The main concepts attributed to CI\/CD are continuous integration, continuous delivery, and continuous deployment.<\/p>\n\n\n\n<p>The issues that development and operations teams may encounter when integrating new code are resolved by CI\/CD.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/1_ezikvlWu0UAwFfh3ko8LXQ-1024x476-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"476\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/1_ezikvlWu0UAwFfh3ko8LXQ-1024x476-1.png\" alt=\"cicd\" class=\"wp-image-13325\"\/><\/a><\/figure>\n\n\n\n<p>The three primary approaches for the continuous method are:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/cloudkul.com\/blog\/continuous-integration-continuous-delivery-and-continuous-deployment\/\" target=\"_blank\" rel=\"noreferrer noopener sponsored nofollow\"><strong>Continuous Integration<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudkul.com\/blog\/continuous-integration-continuous-delivery-and-continuous-deployment\/\"><strong>Continuous Delivery<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudkul.com\/blog\/continuous-integration-continuous-delivery-and-continuous-deployment\/\"><strong>Continuous Deployment<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Continuous Integration<\/strong><\/h2>\n\n\n\n<p>Continuous integration\u00a0is a\u00a0DevOps software development practice where developers regularly merge their code changes into a central repository, after which automated builds and tests are run. <\/p>\n\n\n\n<p>The key goals of continuous integration are to find and address bugs quicker, improve software quality, and reduce the time it takes to validate and release new software updates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Continuous delivery<\/strong><\/h2>\n\n\n\n<p>Continuous Delivery (CD) is a software delivery approach where development teams create and test code in short, automated cycles to enhance software quality.<\/p>\n\n\n\n<p>This process enables development teams to build, test, and deploy software quickly.&nbsp;<\/p>\n\n\n\n<p>In continuous delivery, every stage\u2014from the merger of code changes to the delivery of production-ready builds\u2014involves test automation and code release automation. <\/p>\n\n\n\n<p>At the end of that process, the operations team can deploy an app to production very quickly and easily.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Continuous Deployment<\/strong><\/h2>\n\n\n\n<p>Continuous Deployment is another step beyond &#8220;Continuous Integration&#8221;, similar to Continuous Delivery.<\/p>\n\n\n\n<p>The difference is that instead of deploying your application manually, you set it to be deployed automatically. <\/p>\n\n\n\n<p><strong>Here, human intervention is not required. <\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Continuous_Delivery_vs._Continuous_Deployment\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Continuous Delivery vs Continuous Deployment<\/mark><\/strong><\/h2>\n\n\n\n<p> Continuous delivery requires manual approval before deployment, whereas continuous deployment will automatically roll out the update once the application has passed test cases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8eb5\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">You should have the following<\/mark><\/strong> &#8211; <\/h2>\n\n\n\n<ol>\n<li>Ubuntu server. <\/li>\n\n\n\n<li>Gitlab private repository which you own or have management permission. <\/li>\n\n\n\n<li>Basic knowledge of git and Linux\/Ubuntu OS.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\"><strong>\u00a0How it will work<\/strong><\/mark><\/h2>\n\n\n\n<ol>\n<li>There will be a Runner (Gitlab runner), installed on your Ubuntu system<\/li>\n\n\n\n<li>The runner will get connected to your repo using the required configurations<\/li>\n\n\n\n<li>Your GitLab will create the job to run on your server when new changes are detected on your default branch(staging)<\/li>\n\n\n\n<li>Your runner installed on the system will run the required command on the server upon invoking from GitLab.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Runners :<\/strong><\/h2>\n\n\n\n<p>GitLab Runner is an application that works with<strong><em> <\/em><a href=\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\">GitLab CI\/CD<\/a><\/strong> to run jobs in a pipeline.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Types of Runners<\/strong><\/h3>\n\n\n\n<ul>\n<li>Group \u2013 Runner available for all projects and subgroups in a group<\/li>\n\n\n\n<li>Shared \u2013 Runner available for use by all projects<\/li>\n\n\n\n<li>Specific \u2013 Runner associated with individual projects<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Let\u2019s get started.<\/mark><\/strong><\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">1. Install Gitlab runner on your <\/mark><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Ubuntu server<\/mark><\/strong><\/h5>\n\n\n\n<p>First, you need to add the official GitLab repository to your Ubuntu server. You can run the following command.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2. <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Simply, download one of the binaries for your system:<\/mark><\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo curl -L --output \/usr\/local\/bin\/gitlab-runner \"https:\/\/gitlab-runner-downloads.s3.amazonaws.com\/latest\/binaries\/gitlab-runner-linux-amd64\"<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-23.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"109\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-23-1024x109.png\" alt=\"runner\" class=\"wp-image-13102\"\/><\/a><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">3. <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Allow it to execute:<\/mark><\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo chmod +x \/usr\/local\/bin\/gitlab-runner<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-27.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"37\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-27-1024x37.png\" alt=\"permission\" class=\"wp-image-13106\"\/><\/a><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">4. Create a GitLab CI user:<\/mark><\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell \/bin\/bash<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-29.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"57\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-29-1024x57.png\" alt=\"user\" class=\"wp-image-13108\"\/><\/a><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\"><strong>5. Install and run as a service:<\/strong><\/mark><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo gitlab-runner install --user=gitlab-runner --working-directory=\/home\/gitlab-runner<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-32.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"106\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-06_10-32-1024x106.png\" alt=\"run\" class=\"wp-image-13110\"\/><\/a><\/figure>\n\n\n\n<p><strong>Note:<\/strong> As we above created a user whose name is  &#8220;gitlab-runner&#8221;  should have permission to execute the command in your server. <\/p>\n\n\n\n<p>We need to permit the user with NOPASSWD because when the pipeline runs it will not ask for the password.<\/p>\n\n\n\n<p>Edit your sudoers file <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">vi \/etc\/sudoers<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-30_15-28.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"456\" data-id=\"12770\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-30_15-28-1024x456.png\" alt=\"edit\" class=\"wp-image-12770\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><strong>define your user with No password permission<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\"> start the GitLab runner using the below command <\/mark><\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo gitlab-runner start<\/pre>\n\n\n\n<p><strong>Now, You can check your runner status<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">service gitlab-runner status<\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-11-08-09.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"306\" data-id=\"12742\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-11-08-09-1024x306.png\" alt=\"status\" class=\"wp-image-12742\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Now, create the Repository on your Gitlab<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-12-59-29.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"520\" data-id=\"12753\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-12-59-29-1024x520.png\" alt=\"repo\" class=\"wp-image-12753\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Configure and register your runner on your server<\/p>\n\n\n\n<p>To configure your runner, open GitLab and open the repository where you want to set up your deployment.<\/p>\n\n\n\n<p>Go to Project\u2019s settings &gt; CI\/CD and expand the runner section.<\/p>\n\n\n\n<p>You will see below information, <strong>GitLab instance URL<\/strong>&nbsp;&amp;&nbsp;<strong>token<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-04_16-24.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"437\" data-id=\"12990\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-04_16-24-1024x437.png\" alt=\"git\" class=\"wp-image-12990\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">6. Now, Run the below command on your Ubuntu server<\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo gitlab-runner register<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-13-25-33.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"151\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-13-25-33-1024x151.png\" alt=\"run\" class=\"wp-image-12755\"\/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"6239\">This will start a short configuration with the following steps:<\/h3>\n\n\n\n<ul>\n<li>Enter the GitLab instance URL (for example,&nbsp;<a href=\"https:\/\/gitlab.com\/)\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/gitlab.com\/)<\/a>&nbsp;\u2014&nbsp;Simply copy and paste the URL exactly as shown in GitLab.<\/li>\n\n\n\n<li>Enter the registration token \u2014&nbsp;Copy and paste the registration token exactly as shown in GitLab.<\/li>\n\n\n\n<li>Enter a description for the runner&nbsp;\u2014 Simply hit the&nbsp;Enter\/Return&nbsp;key to use the default name.<\/li>\n\n\n\n<li>Enter tags for the runner (comma-separated) \u2014\u00a0You can leave this empty for now. You can change this later from GitLab. Hit the\u00a0Enter and Return\u00a0keys to continue.<\/li>\n\n\n\n<li>Enter optional maintenance note for the runner \u2014&nbsp;You can leave this empty.<\/li>\n\n\n\n<li>Enter an executor: custom, docker, ssh, VirtualBox, docker-ssh+machine, Kubernetes, docker-ssh, parallels, shell, docker+machine \u2014<br>If you have installed Docker, you can specify the&nbsp;<code>docker<\/code>&nbsp;executor.<\/li>\n\n\n\n<li>Enter the default Docker image (for example, ruby:2.7) \u2014&nbsp;You can use the default and hit the&nbsp;Enter\/Return&nbsp;key to continue.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-14-47-18.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"315\" data-id=\"12757\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2022\/12\/Screenshot-from-2022-12-30-14-47-18-1024x315.png\" alt=\"run\" class=\"wp-image-12757\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p id=\"3b00\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">get back to Gitlab, and open&nbsp;<code>Settings &gt; CI\/CD<\/code>&nbsp;and expand the Runners configuration.<\/mark><\/strong><\/p>\n\n\n\n<p id=\"4fb1\"><strong>You will see the runner as being registered.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-6 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-04_16-26.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"506\" data-id=\"12991\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-04_16-26-1024x506.png\" alt=\"cicd\" class=\"wp-image-12991\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">7. <mark style=\"background-color: rgba(0, 0, 0, 0);\" class=\"has-inline-color has-black-color\">Here, We have two branches (the staging branch and the main branch).<\/mark><\/h5>\n\n\n\n<p>T<mark style=\"background-color: rgba(0, 0, 0, 0);\" class=\"has-inline-color has-black-color\">he developer pushes code in the staging branch and whenever we merge the staging branch into the main branch, the code will automatically get deployed on the server.<\/mark><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-02_10-41.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"288\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-02_10-41-1024x288.png\" alt=\"cicd\" class=\"wp-image-12774\"\/><\/a><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">8. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\"><strong>Now, add files &#8220;file1&#8221; and &#8220;file2&#8221; in the<\/strong> <\/mark><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">staging branch and then merge them <\/mark><\/strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\"><strong>into the main branch <\/strong><\/mark><\/h5>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-7 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-02_12-04.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"181\" data-id=\"12786\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-02_12-04-1024x181.png\" alt=\"cicd\" class=\"wp-image-12786\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">9. Add and configure the <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">gitlab-ci.yml file in the main branch <\/mark><\/strong><\/h5>\n\n\n\n<p>In the&nbsp;<code>.gitlab-ci.yml<\/code>&nbsp;file, you can define:<\/p>\n\n\n\n<ul>\n<li>The scripts you want to run.<\/li>\n\n\n\n<li>Other configuration files and templates you want to include.<\/li>\n\n\n\n<li>Dependencies and caches.<\/li>\n\n\n\n<li>The commands you want to run in sequence and those you want to run in parallel.<\/li>\n\n\n\n<li>The location to deploy your application.<\/li>\n\n\n\n<li>Whether you want to run the scripts automatically or trigger any of them manually<\/li>\n<\/ul>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">When you add a&nbsp;<code>.gitlab-ci.yml<\/code>&nbsp;file to your repository, GitLab detects it and an application called&nbsp;<a href=\"https:\/\/cloudkul.com\/blog\/how-to-deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\">GitLab Runner<\/a>&nbsp;runs the scripts defined in the jobs. <\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">stages:          # List of stages for jobs, and their order of execution\n  - build main\n\nbuild-job main:       \n  stage: build main\n  script:\n    - echo \"Compiling the code...\"\n    - echo \"Compile complete.\"\n    - sudo rm -rf \/home\/ubuntu\/*\n    - sudo cp -r * \/home\/ubuntu\/\n    - sudo cp -r . \/home\/ubuntu\/\n    - sudo rm -rf *\n  tags :  \n     - server1-tag\n  only :\n     - main <\/pre>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">here, I have added <\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-10_16-57.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"440\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-10_16-57-1024x440.png\" alt=\"code\" class=\"wp-image-13332\"\/><\/a><\/figure>\n\n\n\n<p>merge the code into the main branch, GitLab CI\/CD not only executes the jobs but also shows you what\u2019s happening during execution, just as you would see in your terminal: <\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-8 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-02_11-59.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"496\" data-id=\"12782\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-02_11-59-1024x496.png\" alt=\"code\" class=\"wp-image-12782\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Now, Our job has succeeded, <a href=\"https:\/\/docs.gitlab.com\/ee\/ci\/yaml\/img\/job_running_v13_10.png\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-10_16-53.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"64\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/2023-01-10_16-53-1024x64.png\" alt=\"job\" class=\"wp-image-13329\"\/><\/a><\/figure>\n\n\n\n<p>As you can see from the above screenshot file1 and file2 have been deployed on the server through GitLab ( CI\/CD)<\/p>\n\n\n\n<p><strong>You may also visit our Magento development services and quality&nbsp;<\/strong> <strong><a href=\"https:\/\/store.webkul.com\/Magento-2.html\">Magento 2 Extensions<\/a><\/strong>.<\/p>\n\n\n\n<p><strong>For further help or queries, please&nbsp;<a href=\"https:\/\/cloudkul.com\/contact\/\">contact<\/a>&nbsp;us or raise a&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">ticket<\/a>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, We\u2019ll learn how to set CI\/CD (Gitlab CI\/CD) between the Gitlab and <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,35,87,46,341,36],"tags":[813,812,206,654,808,53,815],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deploy code from GitLab to Server using Gitlab CI\/CD - Cloudkul<\/title>\n<meta name=\"description\" content=\"GitLab is an open-source collaboration platform that provides powerful features beyond hosting a code repository. GitLab provides its own CI\/CD feature.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deploy code from GitLab to Server using Gitlab CI\/CD - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"GitLab is an open-source collaboration platform that provides powerful features beyond hosting a code repository. GitLab provides its own CI\/CD feature.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-17T11:03:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-18T08:14:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/Untitled-Diagram.drawio-10.png\" \/>\n<meta name=\"author\" content=\"Mohit Tiwari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\",\"name\":\"Deploy code from GitLab to Server using Gitlab CI\/CD - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2024-12-17T11:03:32+00:00\",\"dateModified\":\"2024-12-18T08:14:36+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7\"},\"description\":\"GitLab is an open-source collaboration platform that provides powerful features beyond hosting a code repository. GitLab provides its own CI\/CD feature.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deploy code from GitLab to Server using Gitlab CI\/CD\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7\",\"name\":\"Mohit Tiwari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Mohit Tiwari\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/mohitkrtiwari-cloud767\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deploy code from GitLab to Server using Gitlab CI\/CD - Cloudkul","description":"GitLab is an open-source collaboration platform that provides powerful features beyond hosting a code repository. GitLab provides its own CI\/CD feature.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/","og_locale":"en_US","og_type":"article","og_title":"Deploy code from GitLab to Server using Gitlab CI\/CD - Cloudkul","og_description":"GitLab is an open-source collaboration platform that provides powerful features beyond hosting a code repository. GitLab provides its own CI\/CD feature.","og_url":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/","og_site_name":"Cloudkul","article_published_time":"2024-12-17T11:03:32+00:00","article_modified_time":"2024-12-18T08:14:36+00:00","og_image":[{"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2023\/01\/Untitled-Diagram.drawio-10.png"}],"author":"Mohit Tiwari","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/","url":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/","name":"Deploy code from GitLab to Server using Gitlab CI\/CD - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2024-12-17T11:03:32+00:00","dateModified":"2024-12-18T08:14:36+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7"},"description":"GitLab is an open-source collaboration platform that provides powerful features beyond hosting a code repository. GitLab provides its own CI\/CD feature.","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/deploy-code-from-gitlab-to-server-using-gitlab-ci-cd\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Deploy code from GitLab to Server using Gitlab CI\/CD"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/d65bf252186a357da67ead26747e47b7","name":"Mohit Tiwari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d958ee0f8ad4fe891d737cc821536709?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Mohit Tiwari"},"url":"https:\/\/cloudkul.com\/blog\/author\/mohitkrtiwari-cloud767\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/12672"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=12672"}],"version-history":[{"count":201,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/12672\/revisions"}],"predecessor-version":[{"id":19090,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/12672\/revisions\/19090"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=12672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=12672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=12672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}