Search This Blog

Breaking

Monday, 31 May 2021

May 31, 2021

[Jenkins] How to set build Number and Build description from your Jenkin file?

 If you are using same job for your QA, Stage and Prod environment [Though I don't recommend it], and from the build page, you want to show this information by replacing build number to your environment  and By giving a description under your new build name, then you can easily do it by just putting these 2 information's in your Jenkin file:


currentBuild.displayName = "${params.Tags}";

currentBuild.description = "${params.Environment}";

In my case, I am reading this information from the params, but if you want, you can hard code it also.

Once set, and when you will ran your job, the build information will appear like this in your Jenkin build page:





Wednesday, 26 May 2021

May 26, 2021

How to connect your Jenkin job to Microsoft Teams?

This was an idea where I was thinking to link our Jenkin Job to Microsoft teams, so that from the team's channel only, we could get the build status and other details.

So, If you are also planning for the same, you can follow the below steps.

Step 1: Create a channel in your team.





2. Inside that channel, click on connectors.

Note: If this channel is newly created, then the connectors option takes some time to get reflected.





3. Go to the Incoming webhook option there.



4. Click on Add Then again Add. Now it will come with an option as Configure.




5. Click on configure. Give your incoming webhook a name. And click on create.



6. Once you will click on create, It will create a URL.


7. copy the URL and click on done. Save URL at someplace for now.

8. Now go to Jenkins. Add office 365 plugin if not already installed.



9. After the plugin will be added there, you will see the office 365 tab in your jobs.











10. Click on it. You will see add webhook option there. Click on it.







11. Add the copied URL here. Give any random name.







12. Click on the advanced tab and select when do you want to get notified.











13. Click on save. 

14. Run your build. You will see notifications like this coming in your teams as per your selections.







Tuesday, 18 May 2021

May 18, 2021

How to configure groovy in Mac Intelij?

When I did the groovy set up on a windows machine, I never thought I would like an article about the same [How to configure groovy in Mac intelij] when I will do it in mac. The reason is obvious: It's not straightforward in mac. So let me share the steps which I followed to install groovy in mac:

1. You can make sure you have  brew (Homebrew) installed in your mac. To check this, You can run thsi command in the terminal:

brew --version

If it returns something like:

Homebrew 3.1.7

It means you have brew installed in your mac.


2. If the above command says, the brew is not found/recognized, it means you have to install it.

You can open this site:

https://brew.sh/

And inside that, you will see, Install homebrew.


Copy the command and paste it to the terminal and run it.


It will take some time, but it will install brew in your mac.


3. Once homebrew is in your machine, you can install groovy with this command in terminal:


brew install groovy


4. Once groovy will be installed in your machine, you can check it by running this command:


groovy --version


5. Now open IntelliJ for creating a new groovy project. It will ask you to do the setup the groovy library for groovy.

6. To give the path of the groovy library in IntelliJ, first, we will have to know the path of groovy installation in our machine. We can check the path of groovy installation with the help of the below command:

where groovy


in my case, the above command gave below path:


/usr/local/bin/groovy



7. Now the problem comes in mac. Because when you click on create in IntelliJ for setting up the library:

First, you can not figure out this path
Second, after figuring out also, you can not figure out the lib folder which needs to add in IntelliJ.

8. So if your groovy path is also the same as mine, you first need to navigate to this location.
This will be inside your  Mac folder, not in users.


9. After figuring out groovy in your mac, you need to find out the lib folder. Because in IntelliJ, the lib folder needs to be added. This can be found inside the groovy folder.




10.  Now add it in IntelliJ.







It will add now.

Note: To run groovy, you must have java also configured.
















Wednesday, 12 May 2021

May 12, 2021

[Jenkins] How to run same Jenkinsfile for Windows and Mac (Unix/Linux) Machine?

Recently I came across to a problem where I have to run the same Jenkins File which I was running in Linux (Mac) machine to the other Windows machine as well. The first thing which came in my mind (I believe will come to everyone's mind too) is to identify the machine OS and run the script accordingly.

While googling it's solution, reading stack overflow answers, Jenkins documentations, I came across to a solution, which helped me to put a condition in my Jenkins file based on the OS.

Jenkin provides a method isUnix() to check the os Type. So if your code is running in Unix/Linux or mac machine, you can put a condition like this:






 if(isUnix()) {

sh "mvn clean test" // Linux related stuff

} else {

bat "mvn clean test" // Windows related stuff

}

With this way, you can put the windows and Linux configurations separately in your Jenkins file.




May 12, 2021

Jenkins: [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [Fix]

 Recently, When I was trying to run my Automation Job in Windows environment, I stuck with one issue, Where in Jenkin console, It started throwing error:

 No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?







I first navigated to that directory where Jenkin took the clone and later ran my maven command there. It worked fine and didn't give any error. It helped me to narrowed down to find the soltution.

In local, where my pom.xml file was present, I tried to run the same command , and here also it worked.

I started googling about this failure.  I found few answer in stackoverflow, but the which which worked in my case was:

to add 

<fork>true</fork>

inside my pom.xml file.

Now My pom file started looking like this:

<plugins>

    <plugin>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>3.1</version>

        <configuration>

            <fork>true</fork>

        </configuration>

    </plugin>

</plugins>


This worked fine and didn't impacted the other jobs also which I was running.

Link: StackOverFlowLink

Friday, 7 May 2021

May 07, 2021

[Jmeter]-> Running Jmeter JMX files from Jenkin with the help of Maven Project

 Recently I was trying to run the JMeter project with Jenkin and I found some interesting information about it. Let me share what steps I followed. 





1. First I create a java maven project in my local machine.

2. Then create a jmeter directory inside your src/test path.

3. Inside this, put your jmx file.

4. Now go to your pom.xml file. And put the following plugin and dependencies.

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>


<plugin>
<groupId>de.codecentric</groupId>
<artifactId>jmeter-graph-maven-plugin</artifactId>
<version>0.1.0</version>
<configuration>
<inputFile>${project.build.directory}/jmeter/results/20170319-BlazeDemo Home Page.jtl</inputFile>
<graphs>
<graph>
<pluginType>ResponseTimesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/BlazeDemo Request.png</outputFile>
</graph>
</graphs>
</configuration>
</plugin>


</plugins>
5. That's it. Now open the terminal and run the following command:

mvn verify

6. It will run your jmeter result in non -gui mode.

Before that, make sure, you have put following changes in jmeter user.properties file. (It will be inside jmeter bin file and this is needed for reporting purposes.)

jmeter.save.saveservice.output_format=xml

7. Once this local setup will be ready, you can create maven job in jenkin.

8. Inside that JSON, add this command in pre-built steps.

9. In the post-build section, add this path for the report to come in the Performance report plugin:

**\target\jmeter\results\*.jtl

10. Now save the job and click on the build.

Wednesday, 5 May 2021

May 05, 2021

[Karate API Automation Framework] How to run test cases with the help of Jenkin Maven Job?

 So If you have set up your API Automation project with the Karate framework, and now you are planning to run your automated test cases with the help of Jenkin, you can do it by creating jobs in your Jenkin.

You can create a Jenkin job as a freestyle project or you can create with the help of a pipeline.

Here in this article, we will try to create a freestyle job in Jenkin for API Automated test cases. We can follow below steps:

Steps 1: Click on New Item, give a name for your API Automation

Step 2: Select Maven  project




Step 3: Click on Ok. It will load the configuration page. Select or make sure JDK is selected.







Step 4: Now select the source code management. in this case, git. Copy the git URL for your project.




Step 5: Enter the git repo URL along with branch detail.




Step 6: Now in the pre-build step, enter the shell (Linux or mac) or batch command (windows)





mvn clean test -DargLine='-Dkarate.env=e2e' -Dkarate.options="--tags @Smoke" -Dtest=CucumberReport -DfailIfNoTests=false

There are 3 parts to this command:

mvn clean test: It will search the test class.

Dkarate.env: It will set up the environment, in this case e2e

Dkarate. options tag: It will set up the tags.

Step 8; Make sure in the build section, pom is coming. 





Step 7: In post-build action, use cucumber report. (Cucumber report plugin need to be added in Jenkin).
If it is added, it will come in the option.



Step 8: Click on advanced




Step 9: Enter the report path. (This path is for karate 1.0.1)




Step 10. Click on Save.

Step 11: Click on Build Now.




Step 12: After the build is successful, You will see the cucumber report.


Step 13: Clicking on the cucumber report will show you the summary of all the test cases.