How to run Rest API Tests in GitLab CI/CD

HOME

This tutorial explains the process to run the Rest API Tests in GitLab pipeline. This is a significant step towards achieving CI/CD. Ideally, the tests need to run after any change (minor/major) before merging the change to master branch. Suppose there are 100 changes in a day, and any QA won’t want to start the tests manually 100 times in a day. So, now adding tests to GitLab pipeline comes to the picture. We can add a test stage to the pipeline and the tests will run automatically when the pipeline run, or we can schedule the tests to run automatically every hour or day using GitLab pipeline.

Pre-Requisite:

  1. Rest Assured – 4.3.3
  2. Java 11
  3. Maven / Gradle
  4. TestNG /JUnit
  5. GitLab account

To use GitLab CI/CD, we need to keep 2 things in mind:-

a) Make sure a runner is available in GitLab to run the jobs. If there is no runner, install GitLab Runner and register a runner for your instance, project, or group.

b) Create a .gitlab-ci.yml file at the root of the repository. This file is where you define your CI/CD jobs.

Step 1 – Create a new Maven Project

Step 2 – Add the below-mentioned pom.xml that shows all the dependencies need to add to the project

<dependencies>
      <!-- https://mvnrepository.com/artifact/org.testng/testng -->
      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>7.4.0</version>
         <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
      <dependency>
         <groupId>io.rest-assured</groupId>
         <artifactId>rest-assured</artifactId>
         <version>4.3.3</version>
         <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.json/json -->
      <dependency>
         <groupId>org.json</groupId>
         <artifactId>json</artifactId>
         <version>20210307</version>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <!-- Compiler plug-in -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
               <source>11</source>
               <!--For JAVA 8 use 1.8-->
               <target>11</target>
               <!--For JAVA 8 use 1.8-->
            </configuration>
         </plugin>
         <!-- Added Surefire Plugin configuration to execute tests -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
               <suiteXmlFiles>
                  <suiteXmlFile>testng.xml</suiteXmlFile>
               </suiteXmlFiles>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

It is needed to add maven-surefire plugin to run the TestNG tests through command line. To know more about this, please refer to this tutorial.

Step 3 – Create the Test Code to test the Rest API

Here, 2 tests are created. One of the tests get all the employee data (GET) whereas another test creates an employee (POST).

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

import org.json.JSONObject;
import org.testng.annotations.Test;

import io.restassured.http.ContentType;

public class RestAPIDemo {

	@Test(description = "To get the details of employee with id 2", priority = 0)
	public void verifyUser() {

		// Given
		given()
				// When
				.when().get("http://dummy.restapiexample.com/api/v1/employee/2")
				// Then
				.then().statusCode(200).statusLine("HTTP/1.1 200 OK")
				// To verify booking id at index 3
				.body("data.employee_name", equalTo("Garrett Winters"))
				.body("message", equalTo("Successfully! Record has been fetched."));
	}

	@Test(description = "To create a new employee", priority = 1)
	public void createUser() {

		JSONObject data = new JSONObject();

		// Map<String, String> map = new HashMap<String, String>();

		data.put("employee_name", "APITest");
		data.put("employee_salary", "99999");
		data.put("employee_age", "30");

		// GIVEN
		given().baseUri("http://dummy.restapiexample.com/api").contentType(ContentType.JSON).body(data.toString())

				// WHEN
				.when().post("/v1/create")

				// THEN
				.then().statusCode(200).body("data.employee_name", equalTo("APITest"))
				.body("message", equalTo("Successfully! Record has been added."));

	}
}

Step 4 – Create testng.xml to run the tests through TestNG

Now, let’s create a testng.xml to run the TestNG tests. If JUnit is used instead of TestNG, then this step is not needed.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="com.example.RestAssured_TestNG_Demo.RestAPIDemo"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Step 5 – Run the tests through the command line

Now, let us execute the tests through the command line. Go to the place where pom.xml of the project is placed and use the below command to run the tests. This step makes sure that all the tests are running as expected.

GitLab Section

Step 6 – Create a blank project in GitLab

Refer to this tutorial to create a new blank project – How to create a new project in GitLab.

Step 7 – Push the project from the local repository to GitLab Repository

Refer to this tutorial to push the changes – How to push new local GIT Repository to GitLab.

Step 8 – Create .gitlab-ci.yml file in the project in GitLab

It is a YAML file where you configure specific instructions for GitLab CI/CD. In the .gitlab-ci.yml, we can define:

  • The scripts you want to run.
  • Other configuration files and templates you want to include.
  • Dependencies and caches.
  • The commands you want to run in sequence and those you want to run in parallel.
  • The location to deploy your application.
  • Whether you want to run the scripts automatically or trigger any of them manually.

image: adoptopenjdk/maven-openjdk11

stages:
  - test

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

test:
  stage: test
  allow_failure: true

# Run the tests
  script:
    - mvn $MAVEN_OPTS clean package
    - mvn compile test

# Store artifacts
  artifacts:
    when: always
    name: "report"
    paths:
    - target/surefire-reports/*
    expire_in: 1 h

Step 9 – Run the tests in the GitLab pipeline

Now, when a new change is committed, a pipeline kicks off and it runs all the tests.

Step 10 – Check the status of the pipeline

Once the Status of the pipeline changes to either failed or passed.. that means the tests are already executed. Here, the pipeline is passed with brown color means that the execution of the test is completed with some failures.

I have added an artifact in the gitalb-ci.yml with the name “report”. This artifact creates a folder with the name “report” and the reports in this folder come from the path /target/surefire-reports. This artifact gives us an option to download the reports or browse the report. This report will be available for 1 hour only as mentioned in the gitlab-ci.yml.

Step 11 – Download the report

Click on the Download button and the report zip file is downloaded. Unzip the folder, and it contains all different types of surefire-reports.

Example of Emailable-Report.html

Example of Index.html

Congratulations. This tutorial has explained the steps to run Selenium tests in GitLab CI/CD. Happy Learning!!

Advertisement

Run Selenium Tests in GitLab CI/CD

HOME

This tutorial explains the process to run the Selenium Tests in the GitLab pipeline. This is a very important step towards achieving CI/CD. Ideally, the tests need to run after any change (minor/major) before merging the latest change to the master branch. Suppose there are 100 changes merged to the master branch in a day and it is expected to run the tests every time before deployment. In this case, any QA won’t want to start the tests manually 100 times in a day. Now, what should be done to overcome this problem. Now, adding tests to the GitLab pipeline comes into the picture. We can add a test stage to the pipeline and the tests will run automatically when the pipeline run.

Pre-Requisite:

  1. Selenium
  2. TestNG/JUnit (for Assertions)
  3. Java 11
  4. Maven/ Gradle
  5. GitLab Account

What is GitLab CI/CD Workflow?

Once the proposed changes are built, then push the commits to a feature branch in a remote repository that’s hosted in GitLab. The push triggers the CI/CD pipeline for your project. Then, GitLab CI/CD runs automated scripts (sequentially or in parallel) to build as well as to test the application. After a successful run of the test scripts, GitLab CI/CD deploys your changes automatically to any environment (DEV/QA/UAT/PROD). But if the test stage is failed in the pipeline, then the deployment is stopped.

After the implementation works as expected:

  • Get the code reviewed and approved.
  • Merge the feature branch into the default branch.
    • GitLab CI/CD deploys your changes automatically to a production environment.

To use GitLab CI/CD, we need to keep 2 things in mind:

a) Make sure a runner is available in GitLab to run the jobs. If there is no runner, install GitLab Runner and register a runner for your instance, project, or group.

b) Create a .gitlab-ci.yml file at the root of the repository. This file is where CI/CD jobs are defined.

The Selenium tests run on a headless browser in the pipeline.

What is a headless browser?

A headless browser is like any other browser, but without a Head/GUI (Graphical User Interface).  A headless browser is used to automate the browser without launching the browser. While the tests are running, we could not see the browser, but we can see the test results coming on the console.

To explain, I have created 2 Selenium tests and used TestNG for asserting the tests. The tests will run on a headless Chrome browser. One more thing to keep in mind is that when tests run on a headless Chrome browser, the window screen won’t be full screen. So, the screen needs to be maximized explicitly otherwise some of the tests would fail.

Step 1 – Create a new Maven Project

Step 2- Add the dependencies to the POM.xml

Add the below-mentioned dependencies that need to add to the project to the pom.xml in Maven Project.

 <dependencies>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.5</version>
            <scope>test</scope>
        </dependency>
                   
    </dependencies>
    <build>
     <plugins>
     
     <!--  Compiler Plugin -->
    
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
           <source>11</source>
           <target>11</target>
        </configuration>
    </plugin>
     
      <!--  Plugin used to execute tests -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
     </plugins>
  </build>
</project>

As explained in one of the previous tutorial, it is needed to add the maven-surefire-plugin to run the TestNG tests through the command line.

Step 3 – Create the Test Code

This is the BaseTest Class where the WebDriver is initialized, headless mode, full screen, and at the end close the WebDriver.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import io.github.bonigarcia.wdm.WebDriverManager;

public class BaseTest {
	
	WebDriver driver;
	
	@BeforeMethod
	public void beforeTests() {
        WebDriverManager.chromedriver().setup();
        ChromeOptions options=new ChromeOptions();
        options.setHeadless(true);
        options.addArguments("window-size=1920,1200");
        driver=new ChromeDriver(options);
        driver.get("https://opensource-demo.orangehrmlive.com/");
    }

	@AfterMethod
    public void afterTests() {
        driver.quit();
    }

}

There are 2 different pages that need to be tested – LoginPage and ForgetPasswordPage

LoginPage contains the tests to log in to the application. After successful login, the application moves to the next webpage – HomePage. You can see that BaseTest class is extended in both the Test classes.

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

@Test
public class LoginPage extends BaseTest{
	
	@Test
	public void validCredentials() throws InterruptedException {

	        driver.findElement(By.name("txtUsername")).sendKeys("Admin");	        
	        driver.findElement(By.name("txtPassword")).sendKeys("admin123");
	        driver.findElement(By.id("btnLogin")).click();
	         String newPageText = driver.findElement(By.xpath("//*[@id='content']/div/div[1]/h1")).getText();
	        System.out.println("newPageText :" + newPageText);
	        Assert.assertEquals(newPageText,"Dashboard");

	}

}

ForgetPasswordPage

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

@Test
public class ForgetPasswordPage extends BaseTest{
	
	@Test
	public void getHeading() {
		
		Thread.sleep(1000);
		driver.findElement(By.xpath("//*[@id='forgotPasswordLink']/a")).click();
		String heading = driver.findElement(By.xpath("//*[@id='content']/div[1]/div[2]/h1")).getText();
		System.out.println("Title : "+ heading );
		Assert.assertEquals(heading, "Forgot Your Password?");
	}
	
}

Step 4 – Create testng.xml to run the tests

Now, let’s create a testng.xml to run the TestNG tests. If JUnit is used instead of TestNG, then this step is not needed.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="org.example.DockerDemo.LoginPage"/>
      <class name="org.example.DockerDemo.ForgetPasswordPage"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Step 5 – Run the tests through command line

Now, let us execute the tests through the command line. Go to the place where the pom.xml of the project is placed and use the below command to run the tests. This step makes sure that all the tests are running as expected.

mvn compile test

GitLab Section

Step 6 – Create a blank project in GitLab

To know, how to create a blank new project in GitLab, please refer to this tutorial.

Step 7 – Push the project from local repository to Gitlab Repository

To know, how to push the changes in GitLab, please refer to this tutorial.

Step 8 – Create a .gitlab-ci.yml file in the project in GitLab

There are many ways to create a new file in GitLab. One of the ways is to create a file as shown in the below image.

It is a YAML file where you configure specific instructions for GitLab CI/CD. In the .gitlab-ci.yml, we can define:

  • The scripts you want to run.
  • Other configuration files and templates you want to include.
  • Dependencies and caches.
  • The commands you want to run in sequence and those you want to run in parallel.
  • The location to deploy your application to.
  • Whether you want to run the scripts automatically or trigger any of them manually.
image: markhobson/maven-chrome

stages:
  - test

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

test:
  stage: test
  allow_failure: true

# Run the tests  
  script:
    - mvn $MAVEN_OPTS clean package
    - mvn compile test

# Store artifacts
  artifacts:
    when: always
    name: "report"
    paths:
    - target/surefire-reports/*
    expire_in: 1 h

Image – markhobson/maven-chrome is used in this test. It is a docker image for Java automated UI tests.

This gitlab-ci.yml has only 1 stage – a test that contains the command to run the tests as well as also create an artifact that contains all the surefire reports which can be saved as Test Evidence.

Step 9 – Run the tests in the GitLab pipeline

Now, when a new change is committed, a pipeline kicks off and it runs all the tests.

Step 10 – Check the status of the pipeline

Once the Status of the pipeline changes to either failed or passed.. that means the tests are already executed.

As you can see the Status is failed here which means that the execution is completed. Let us see the logs of the execution it shows that out of 2 tests, 1 test passed and 1 test failed. This shows that tests are running successfully in the GitLab pipeline.

As I have added an artifact also in the gitalb-ci.yml, which is highlighted in the image. This artifact creates a folder with the name “report” and the reports in this folder come from the path /target/surefire-reports. This artifact gives us the option to download the reports or browse the report. This report will be available for 1 hour only as mentioned in the gitlab-ci.yml.

Step 11 – Download the report

Once, will click on the download button, it will download “report.zip”. Unzip the folder and it looks like something as shown below:

Example of Emailable-Report.html

Example of Index.html

Congratulations. This tutorial has explained the steps to run Selenium tests in GitLab CI/CD. Happy Learning!!

How to install Git on Windows 10

HOME

This tutorial explains the steps to install Git on Windows 10.

Step 1 – To install Git, go to – Git (git-scm.com). I want to install Git on Windows, so can use highlighted option to install Git.

The latest version here is 2.34.1.

Step 2 – Save the Git.exe file.

Step 3 – Now open the installer you have downloaded and go through the installation process. Unless you know what you are doing, leave all settings to their defaults. Click the Next button.

Step 4 – Select the destination location where GIT will be installed. You can continue with the default location as shown below, or use the installation path suggested by Git. Click the Next button.

Step 5 – In this step, you need to select components to be installed. Apart from the pre-selected options, you may also want to select “Add a Git Bash Profile to Windows Terminal”. This can be useful later on, especially if you plan to use Visual Studio Code or other IDEs that have a built-in terminal window. Click the Next button.

Step 6 Select if you would like to GIT shortcut in the start menu. Click the Next button.

Step 7 – Select the default editor of GIT. I use Notepad++ as the default editor used by GIT.

Click the Next button.

Step 8 – Git hosting tools like GitHub or GitLab already use main as their default branch.

Click the Next button.

Step 9 – Click the Next button.

Step 10 – Click the Next button.

Step 11 – Select SSL/TLS library used by GIT to use for the HTTPS connection. Go with default selection and click the Next button.

Step 12 – Click the Next button.

Step 13 – Click the Next button.

Step 14 – Configure the default behaviour of the git pull command. Click the Next button.

Step 15 – Click the Next button.

Step 16 – Enable file system caching to boost performance, which is the default selection. Click the Next button.

Step 17 – Click the Install button.

Step 18 You will get the below screen after the successful installation of GIT. Click the Finish button. This wizard has also installed a new tool called Git Bash, a terminal alternative for cmd or Powershell.

From Git Bash or terminal of your choice, run the following command:-

git --version

You can also use Windows PowerShell as well.

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

How to add Test Suite in existing Project in ReadyAPI

HOME

The previous tutorial has explained to create a Test in a new project using ReadyAPI. This tutorial explains to add a new Test Suite to the existing project.

Steps to be followed

  1. Create a new Test Suite to old project
  2. Add new Test Case
  3. Add a Test Step
  4. Add Assertions
  5. Run the Test and verify Test Result
  6. Generate Test Report
  7. Sample Test Report

Create a new Test Suite for the old project

Step 1 – Go to the Existing Project as REST Project 1 here. Right-click on Functional Tests and select “New Test Suite”.

Step 2 – Enter a new test suite name. Click the OK button.

Step 3 – ReadyAPI will show the created functional Test Suite in the Navigator.

Add new Test Case

Step 4 – Right-click on the newly created Test Suite and select New Test Case as highlighted on the screen.

Step 5 – Enter a new Test Case name. Click OK.

Add a Test Step

Step 6 – Right-click the test case, to which you want to add the test step, and select Add Step from the context menu.

This image has an empty alt attribute; its file name is image-64.png

I’m selecting to add an HTTP Request.

An HTTP Request test step is a standalone HTTP request that can be used to call any HTTP service. This means you can use it to send an HTTP request through HTTP, HTTPS, or JMS.

Using the test step’s properties, you can specify the request type (GET, POST, or other), target URL, parameters, attachments, and other values. You can also define specific assertions for checking the server response.

Step 7 – To create an HTTP request, you do not need to have a service added to your project. When you add the test step, you will see the New HTTP Request Step dialog:

Test Step name – Specifies the name of a new test step.

Endpoint – Specifies the endpoint, to which the request will be sent.

Extract Params – This allows you to obtain parameters and their values from the URL specified in the Endpoint field.

Parameters – The list of request parameters. To modify them, use the toolbar buttons.

+ or Add Parameter– adds a new parameter.

X or or Delete Parameter– removes the selected parameter.

URL – extracts parameters from an endpoint specified in the ensuing dialog.

Method – specifies the type of the request (GET, POST, PUT, and so on).

Step 8 – This screen shows the addition of HTTP Request to the Test Case User 99999.

Step 9 – Click on HTTP Request and mention the request body as shown in the image. Media Type is configurable. I have selected application/json.

Add Assertions

Step 10 – Add Assertion to the Test Case. Click on Add Assertion button.

Step 11 – In the dialog, select the SLA category on the left and then Response SLA on the right, and click Add:

Step 12 – In the dialog, mention the time in ms to wait for the response and click the OK button.

Run the Test and verify Test Result

Step 13 – To run the Test Case, click on the Send button. The below image shows the successful response.

Test Report Generation

The Create Report dialog configuration varies depending on the report type you select. You can create project reports only on the level of the Functional tests in the Navigator.

Sample Test Report

Congratulations!! We have added a new test suite to the old project as well as run the test and generated the Test Report too.

GitLab Tutorials

HOME

GitLab is the open DevOps platform, delivered as a single application. This makes GitLab unique and creates a streamlined software workflow, unlocking your organization from the constraints of a pieced-together toolchain. Learn how GitLab offers unmatched visibility and higher levels of efficiency in a single application across the DevOps lifecycle.

Chapter 1 How to create a new project in GitLab
Chapter 2 How to Export Eclipse projects to GitLab
Chapter 3 How to Export IntelliJ project to GitLab
Chapter 4 How to Clone a project from GitLab using Eclipse
Chapter 5 How to Clone a project from GitLab using IntelliJ

GitLab CI/CD

Chapter 1 Run Selenium Tests in GitLab CI/CD
Chapter 2 How to run Rest API Tests in GitLab CI/CD

GitLab With Jenkins

Chapter 1 Jenkins GitLab Integration

How to create a new project in GitLab

HOME

In this tutorial, I will explain how we can create a new empty project in GitLab.

Implementation Steps

Step 1 – Login to GitLab using your username and password.

Step 2 – In your dashboard, click the blue New project button. This opens the New project page.

Step 3 – The New project page provides 4 options to select:

  1. Create a blank project.
  2. Create a project using one of the available project templates.
  3. Import a project from a different repository, if enabled on your GitLab instance.
  4. Run CI/CD pipelines for external repositories. 

As I have mentioned earlier, I want to create a new empty project, so I will select open 1 (Create a blank project).

Step 4 – A new page will open. Provide the following information on that page:

  • Project Name – Mention the name of your project in the Project name field – CucumberGradleDemo. You can’t use special characters, but you can use spaces, hyphens, underscores, or even emojis.

  • Project slug – When a name is added, the Project slug auto-populates. The path to your project is in the Project slug field. This is the URL path for your project that the GitLab instance uses. If the Project name is blank, it auto populates when you fill in the Project slug. If you want a different slug, input the project name first, then change the slug after.

  • Project description (optional)  – This field enables you to enter a description for your project’s dashboard, which helps others understand what your project is about. Though it’s not required, it’s a good idea to fill this in.

  • Visibility Level – Select the appropriate Visibility Level for your project.

  • Selecting the Initialize repository with a README option creates a README file so that the Git repository is initialized, has a default branch, and can be cloned.

Select the Create Project button.

Congratulations!!. We have just created a new and empty project in GitLab. Now you can clone this project and start working on it.

How to Export IntelliJ project to GitLab

HOME

What is GitLab?

GitLab is the open DevOps platform, delivered as a single application that spans the entire software development lifecycle. If you’re not using GitLab, your DevOps lifecycle is likely spread across any number of applications. These silos take overhead to integrate, manage, configure, and maintain, slowing down your team and your deployments. Moving to a single application will speed up your workflow and help you deliver better software, faster. To know more about GitLab, click here.

In this article, we will see how to push an existing project to GitLab using Eclipse IDE.

Implementation Steps

Step 1 – Go to Git at the top, select VCS ->VCS Oprations -> Create Git Repository.

This will convert the project to a Git project.

Step 2 – Go to Git option present at the top and then select “Commit” option.

Step 3 – This will show all the files which are uncommitted. Select the files you want to commit and mention a message in the below message box as “New project from IntelliJ to GitLab“. Click on the Commit button.

Step 4 – A window opens where we need to mention the location where the project should be pushed in GitLab.

Click the OK button. It will ask for credentials to the GitLab, provide them.

Step 5 – The below image shows that the latest code is moved to GitLab. Here, the origin branch is used to commit and pushed the changes. If we are using a local branch to commit and push the changes, then we need to create a merge request to merge the code of the new branch to the code of existing origin(master branch).

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!

How to Export Eclipse projects to GitLab

HOME

What is GitLab?

GitLab is the open DevOps platform, delivered as a single application that spans the entire software development lifecycle. If you’re not using GitLab, your DevOps lifecycle is likely spread across any number of applications. These silos take overhead to integrate, manage, configure, and maintain, slowing down your team and your deployments. Moving to a single application will speed up your workflow and help you deliver better software, faster. To know more about GitLab, click here.

In this article, we will see how to push an existing project to GitLab using Eclipse IDE.

Implementation Steps

Step 1 – Go to GitLab and select the project which you want to clone. Click on the blue color “Clone” button and then copy the hyperlink as shown in the image. You can either Clone with SSH or Clone with HTTPS.

Step 2 – Open Eclipse IDE and right-click on the project you want to push and go to the Team ->Share project.

Step 3 – It will add the project to the given repository as shown below image. Select the Finish button.

As you can see, the given project is Git Repository. If the project is not GIT Repository, refer to this tutorial – How to create a new Git Repository  to convert the project in GIT Repository.

Step 4 – Again, Right-Click on the project and go to the Team ->commit.

Step 5 – Select the files you want to commit and click green color + sign or Drag and Drop the files from “Unstaged Changes to Staged Changes“.

This is how the stage files looks like as shown below.

Step 6 – Write the commit message in “Commit Message” and click “Commit and Push“.

Step 7 – Fill in the below details in this window and click the “Preview” button.

URI – This is the URL that we have cloned from GitLab in Step 1.
Host – gitlab.com
Repository path – the path of the project in GitLab (This is auto-populated after entering URI)

Authentication
User – Username of GitLab
Password – password of GitLab

Step 8 – A new window will open which provides the detail of the Destination location of the project. Click the “Preview” button.

Step 9 – Push to the new branch of GitLab Repository and click the Push button.

Step 10 – As this is a new project with a master branch, you can see the whole project migrated in GitLab. If we are not using the master branch, but the local branch, then we need to create a merge request to merge the latest changes in the already existing project in GitLab.

Cheers!!Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

How to Clone a project from GitLab using IntelliJ

HOME

What is GitLab?

GitLab is a web-based Git repository that provides free open and private repositories, issue-following capabilities, and wikis. It is a complete DevOps platform that enables professionals to perform all the tasks in a project—from project planning and source code management to monitoring and security.

Why Use GitLab?

The primary advantage of using GitLab is that it allows all team members to collaborate at all stages of the project. GitLab provides tracking from planning to creation to assist developers in automating the entire DevOps lifecycle and achieving the best results possible. GitLab is becoming increasingly popular among developers due to its extensive set of features and codes building blocks.

In this tutorial, I will explain how we can clone a project from GitLab in IntelliJ.

Implementation Steps

Step 1 – Go to GitLab and select the project which you want to clone. Click on the blue color “Clone” button, then copy the hyperlink as shown in the image. You can either Clone with SSH or Clone with HTTPS.

Step 2 – From the main menu, select Git -> Clone

Another way is File ->New -> Project from Version Control

Step 3 – In the Get from Version Control dialog, specify the URL of the remote repository you want to clone. This is retrieved from Step 1. Click the Clone button.

Step 4 – A dialog box will appear to log in to GitLab. Provide the username and password of GitLab. Select the “Log In” button.

Step 5 – When you import or clone a project for the first time, IntelliJ IDEA analyses it. If the IDE detects more than one configuration (for example, Eclipse and Gradle), it prompts you to select which configuration you want to use. Select the necessary configuration and click the OK button. I have selected the Maven project.

Step 6 – Once I have selected the Maven project, a new dialog box will appear. IntelliJ asks you to either Trust the Project or Preview it in Safe Mode. I trust the project, so I have selected the Trust Project button.

Step 7 – IntelliJ will ask if you want to open the project in the current window or New Window. It is always a good practice to open the project in a New Window.

Step 8 – We have successfully imported the GitLab Repository as shown in the below image.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!

How to Clone a project from GitLab using Eclipse

HOME

What is GitLab?

GitLab is a web-based Git repository that provides free open and private repositories, issue-following capabilities, and wikis. It is a complete DevOps platform that enables professionals to perform all the tasks in a project—from project planning and source code management to monitoring and security.

In this tutorial, I will explain how we can clone a project from GitLab in Eclipse.

Implementation Steps

Step 1 – Go to GitLab and select the project which you want to clone. Click on the blue color “Clone” button then copy the hyperlink as shown in the image. You can either Clone with SSH or Clone with HTTPS.

Step 2 – Open Eclipse and go to File > Import in eclipse as shown in the image.

Step 3 – A window will pop up in which select Git Folder. Under the Git folder, select the option – Projects from Git(with smart import) as shown in the image.

Click on the NEXT button.

Step 4 – A new window will pop up in which select the option – Clone URI as shown in the image.

Click on the NEXT button.

Step 5 – Another window will pop up in which you have to paste the GitLab Repository URL and also GitLab UserID and Password and click on the “Next” button.

URI – This is the URL that we have cloned from GitLab in Step 1.
Host – gitlab.com
Repository path – path of the project in GitLab (This is auto-populated after entering URI)

Authentication
User – Username of GitLab
Password – password of GitLab

Step 6 – Select master and selectWhen fetching a commit, also fetch its tags.

Click on the “Next” button.

Step 7 –  Select the Folder directory in which you want to import the repository.

Click on the Finish button.

Step 8 – We have successfully imported the GitLab Repository as shown in the below image.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!