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!

8 Steps to Configure Jenkins to run your project and schedule it

Introduction

     Jenkins is an open source continuous integration tool written in Java.Jenkins provides continuous integration services for software development. It is a server-based system running in a servlet container such as Apache Tomcat. It supports SCM tools including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, Clearcase and RTC, and can execute Apache Ant and Apache Maven based projects as well as arbitrary shell scripts and Windows batch commands. [Ref: Wikipedia]

Integrate-In-Jenkins

8 Steps to Configure Jenkins to run your project and schedule it

  1. Download Jenkins (.war file)(https://jenkins-ci.org/) and save it in C:\ drive (better to identify the java).
  1. Start Jenkins using command in command prompt (java -jar jenkins.war -httpPort=8080)
  1. Open browser and enter “localhost:8080” to access Jenkins GUI.
  1. Open Manage Jenkins section to configure the software like JDK, Maven and ANT.
    1. JDK Installation: Set the name and JAVA_HOME (Uncheck “Install Automatically”).
    2. Maven Installation: Set the name and MAVEN_HOME (Uncheck “Install Automatically”).
    3. Configure ANT: Set the name and ANT_HOME (Uncheck “Install Automatically”).
  1. Create a new project via “New Item” as “Freestyle project”.
  1. Open project then configure build section and invoke Ant.
    1. Invoke Ant: Set Ant Version and Targets. Enter targets as “clean compile run generatereport”.
    2. In Advance section: Set Build File, means set the correct path of the “build.xml” file.
  1. Click on “Build Now” link to execute the test. Access the running builds from “Build History”. Click on “Console Output” to view the execution progress or status of execution if already done.
  1. Schedule your build based on Minutes, Hours, Day, Month, and Day of the Week (0-7, where 0 and 7 are Sunday).
    1. Inside the selected project, click on “Configure” link and goes to “Build Triggers” section; then select “Build periodically” option.
    2. Enter your schedule in “Schedule” edit field. Example: “H 8 * * *” (this will schedule your build every day at 8h00). If you want to build it in every 5 minutes then mention the schedule as H/5 * * * *

enjoy your Continuous Integration