Automation execution in the DevOps world using GitLab CI/CD

CICD-Pipeline-Devops-Edureka

      GitLab is getting more popularity in recent times. One of the reasons for popularity because it combines the source code repository and CI server. Generally, GitLab composed of source code repository and Runners (open source project which is written in “Go” language). Runners are light-weight agents that trigger the jobs assigned to them with the help of dockers (it is a container). If you have a GitLab server then no need for a separate CI server.

      Here I would like to explain how the automation scripts trigger as a pipeline when the developer commits the developer code into the repository.

Capture      The whole magic happens with help of .gitlab-ci.yml file (YAML). It is a configuration file that you can create on your project’s root. This file automatically runs whenever you push a commit to the server. This triggers a notification to the runner and then it processes the series of tasks you specified in the YAML file. The following are some important configuration parameters in the .gitlab-ci.yml file.

  • image: use docker images. Telling to docker agent that image going to use for execution.
  • stages: define stages (jobs) in a pipeline.
  • stage: defines a job stage (default is test).
  • before_script: override a set of commands that are executed before the job.

     The following are the important eight steps to achieve automation execution in the DevOps world using GitLab CI/CD. Here I have done for Selenium automation with Gitlab CI/CD

Step 1: Create Automation Test Project using TestNG + Maven. Develop automation test cases.

Step 2: Create .gitlab-ci.yml file in the root directory of your automation project and configure before_script, stages and test stage details in .gitlab-ci.yml. Below is the configuration details of .gitlab-ci.yml,

image: maven:3.6.3-jdk-11
  
before_script:
    ################################################################################################
    # Install Xvfb (X virtual framebuffer) packages.                                               #
    # Xvfb (X virtual framebuffer) is an in-memory display server for a UNIX-like operating system # 
    # It implements the X11 display server protocol without any display.                           #
    ################################################################################################
    - apt-get update
    - apt-get -y install gnupg
    - apt-get install -y unzip xvfb libxi6 libgconf-2-4
    
    ##########################
    # Install Java on system #
    ##########################
    - apt-get install -y default-jdk
    
    ##################################################
    # Install Latest Google chrome package on system #
    ##################################################
    - curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
    - echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
    - apt-get -y update
    - apt-get -y install google-chrome-stable
    
stages:
  - test
  
test:
  stage: test
  script:
    - chmod a+x /builds/gitlab_username/sampleautomationproject/chromedriver #If you not given the permission then you may face "java.lang.IllegalStateException: The driver is not executable" error.
    - mvn clean #Compile your scripts
    - mvn test #Run your scripts

Step 3: Login to GitLab Dashboard.

Step 4: Create a New Project in GitLab to keep the automation project > Create a Repository.

Step 5: Commit and push your automation test project to the GitLab automation repository.

Step 6: Just refresh the GitLab and see the Pipeline and Jobs section of CI/CD. You can see your automation scripts are executing.

1

Step 7: Create .gitlab-ci.yml file in the root directory of the development project and configure triggerjob details in .gitlab-ci.yml. Below is the configuration details of .gitlab-ci.yml,

image: maven:latest

stages:
  - build
  - test
  - automationstage

build:
  stage: build
  script:
    - mvn clean

test:
  stage: test
  script:
    - mvn test
    
triggerjob:
    stage: automationstage
    trigger:
        project: gitlab_username/sampleautomationproject
        branch: master

Step 8: Make some changes/add new features in development project and deploy it. Observe that development project pipeline starts, once it success it will trigger the automation stage for automation execution.

2.PNG

     Please try to utilize the above steps to make your automation life easier (with GitLab). In this link https://gitlab.com/sanojs you can find the sample POC which I have implemented for this GitLab CI/CD.

make it perfect!

One thought on “Automation execution in the DevOps world using GitLab CI/CD

Add yours

Leave a comment

Create a website or blog at WordPress.com

Up ↑