Hello, previously we have completed the installation of our CI/CD tools. Let’s see how to use these tools in practice.
First of all, it is better to aware that some packages and plugins must be installed. Besides, we are working on a docker container so some operations we are going to establish and maintain sound a little bit bizarre.
Step 1 — Inside Jenkins Container
Before proceeding, please make sure your Dockerfile file has been built successfully and Maven is installed. Now, if you are inside your Jenkins container, you can start.
- Install Gauge Framework
You can run the following which is recommended by Gauge
apt-key adv --keyserver hkp://pool.sks-keyservers.net --recv-keys 023EDB0Becho deb https://dl.bintray.com/gauge/gauge-deb stable main | tee -a /etc/apt/sources.listapt-get updateapt-get install gauge
This output would appear on your console :
If you type gauge –v command :
As you can see, there are not any gauge plugins installed. You can run the below commands to install some of them :
gauge install html-reportgauge install xml-reportgauge install json-reportgauge install javagauge install spectaclegauge install screenshot
Type gauge –v command to make sure you have installed Gauge and its plugins successfully.
2. Install Google Chrome Package
We need now a browser to run our tests. In this work, we have run our test on Google Chrome.
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb# After you run following command, you would get error
dpkg -i google-chrome-stable_current_amd64.deb
# This is the command to fix this error. Type Yes y if it asks in # the middle of process
apt install ./google-chrome-stable_current_amd64.deb# Again run this command
dpkg -i google-chrome-stable_current_amd64.deb google-chrome --version
If you have some troubles, I highly recommend you to visit the websites :
Step 2— Jenkins Manage Plugins
You should install the necessary plugins on the Jenkins Manage Plugin page.
- Maven Integration
- Sonarqube scanner
- Ansicolor (optional)
Step 3— Jenkins General Configuration
- Add Sonarqube Service
Let’s start with creating a new token and save it to use later :
Next, add credentials for Sonar. The secret will be filled with API Token you have just created. Others are optional.
Now, back to the Jenkins Manage Jenkins / Configure System / Sonarqube Server :
The URL area should be filled as <yourIP>/sonarqube.
2. Add Gitlab Credential
Add your GitLab credentials as shown in the figure :
3. Checking Installation Configurations
In the Global Tool Settings you should check and configure the installations properly :
SONARQUBE SCANNER : (You can install externally if you want.)
Finally, click on the apply and then the save button.
Step 4— Create a Project In Sonarqube
- Click to Create a Project.
- Type a project key as you want.
- You can either create a new token or use existing tokens
- Select Java for programming language and Maven for build technology.
- In the end, you will see a piece of code. Please keep it in somewhere. We are going to use it later.
Step 5 — Create a Job in Jenkins
- Click on Create a New Job button.
- Give a name to your project and select Free Style Project.
- In the Source Code Management, select Git and fill out the git repo URL, branch and select the proper credential.
4. Build Environment (Color ANSI is optional.)
5. Add Invoke Top Level Maven Target build step:
This step could also have been done with a shell script. I want to show you that we can also use this build step to implement Maven commands.
6. Add Execute Sonarqube Scanner build step and fill out according to your Sonarqube project information.
Note that you should fill the first three lines according to your sonar project.
7. Add Execute Shell and add the following code.
After you have done the steps above, just click on apply and save. Afterward, you can start building your job.
SOME IMPORTANT NOTES
- Make sure your environment settings (version of Gauge and its plugin are matching with your pom.xml file)
- This only works with HEADLESS mode. So make sure that you add your chrome driver to the headless mode. Otherwise, you will probably get an error.
- I highly recommend you to use WebDriver Manager.
After your build is finished , you would get an output like this :
Thank you for your time.