Jenkins integrated Robot Framework

This article describes how Jenkins integrates the Robot Framework.

The environment used is as follows:

  • Jenkins 2.326, using docker to install and deploy
  • Agent: Windows10, which installs Java environment and Robot Framework test framework to execute automated test cases.

The specific deployment process is described below.

1, Agent configuration Java environment

You need to use Java commands when starting the agent node, so you need to configure the Java environment.

1. Download and install JDK

JDK download address: https://www.oracle.com/java/technologies/downloads/#java8-windows

Install after download

2. Configure environment variables

New system variable JAVA_HOME, variable value: C: \ program files \ Java \ jdk1 8.0_ three hundred and eleven

Create a new system variable classpath, variable value:.;% JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

Edit the system variable Path and add% JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

Check whether the configuration is successful: java -version

$ java -version
java version "1.8.0_311"
Java(TM) SE Runtime Environment (build 1.8.0_311-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)

2, Add and start windows slave

Open the jenkins platform.

Enter system management - > node management to add a new node

windows node configuration and startup method reference Detailed introduction to continuous integration platform Jenkins

3, Installing the Robot Framework plug-in

Robot Framework plugin is used to collect and publish Robot Framework test results in Jenkins. The following two installation methods are introduced.

Method 1: search the Robot Framework plugin on the plug-in management page for installation and download.

Method 2: if Jenkins cannot connect to the network, you can download the corresponding hpi format plug-in on the computer with internet access and upload it. Robot Framework plugin download address: https://plugins.jenkins.io/robot/#releases , select the corresponding version, enter plug-in management after downloading, click Advanced, and upload and install plug-ins in the upload plug-in column.

4, Mail configuration

Install the plug-in first Email Extension Plugin and Email Extension Template Plugin.

Enter the [system management] - [configuration] page and set the system administrator address:

Pull down to find [Extended E-mail Notification] for configuration.

Configure message content template

If you want to view the mail sending log, you can check Enable Debug Mode, and turn it off after the mail configuration is OK:

You can also set the default trigger method here. This is a global setting. Click Default Triggers

Enter the [email notification], and the configuration method is the same as before. After the configuration is completed, test whether the email can be sent successfully.

If it is an intranet environment, you need to ensure that the Jenkins server can communicate with the mail server.

5, Create project

Introduces two methods of project creation.

Method 1: create a freestyle project

Build configuration

Create a new free style project and set the agent node for the project to run. The label is the label specified when adding windows slave.

I don't set source management and triggers here, but build manually.

Add the build step and select the windows bat script.

Execute the following robot framework test cases through the tag login:

robot command:

robot -d D:\ProgramWorkspace\DevTest-Notes\CI\jenkins\rf_results --include=login D:\ProgramWorkspace\DevTest-Notes\RobotFramework\PO_demo

Enter the robot command to execute the robot framework use case in the input box:

Configure RF test report

Next, add the post build operation steps. First, add [Publish Robot Framework test results] to configure the RF test report.

Specify report generation location and result threshold

Configure email alerts

Add email reminder

structure

Click build to see the RF report after execution:

Click report HTML to view the detailed log, an error may be reported: Opening Robot Framework report failed

Solution: https://stackoverflow.com/questions/36607394/error-opening-robot-framework-log-failed

Enter [Manage Jenkins], click [Script Console], enter the following commands in the input box and click [Run]:

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","sandbox allow-scripts; default-src 'none'; img-src 'self' data: ; style-src 'self' 'unsafe-inline' data: ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ;")

After execution, you can successfully open the log report.

If Jenkins is restarted, the configuration in this way will be lost. You have to run the above command again.

The second method is to modify / usr / local / bin / Jenkins. In the Jenkins container SH file, which can take effect permanently:

Edit Jenkins SH file, add the following command to the line beginning with exec java:

-Dhudson.model.DirectoryBrowserSupport.CSP="sandbox allow-scripts; default-src 'none'; img-src 'self' data: ; style-src 'self' 'unsafe-inline' data: ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ;"

If the Jenkins container does not have the vi or vim command, you can copy the file, modify it, and then copy it back:

$ docker cp jenkins:/usr/local/bin/jenkins.sh .   #Copy to current directory
$ vi jenkins.sh # Modify Jenkins SH file
$ docker cp jenkins.sh jenkins:/usr/local/bin/jenkins.sh # Copy to container

Restart Jenkins after modification:

$ docker restart jenkins

Method 2: create pipeline project

The second method is to create a new pipeline project.

Like method 1, I do not set source code management and triggers here, but trigger them manually.

Pipeline

The preparation of Pipeline script is very important. It is mainly used to control the test process. The agent to execute the test script is also specified in pipeline.

Jenkinsfile supports two syntax forms:

  • Declarative pipeline - v2. After 5, it is introduced in a structured way.
  • Scripts pipeline - groovy based syntax.

This article is written using Declarative pipeline.

The following script mainly realizes the following functions:

  • Specify proxy node
  • Issue the build script command
  • Add post build RF Report
  • Add email reminder
pipeline {
  agent {
      node {
        label "slave-windows"
        customWorkspace "D:/ProgramWorkspace/DevTest-Notes/CI/jenkins"
    }
  }

  stages {
         stage('intialize') {
            steps {
                echo "begin"
            }
        }
    
        stage('Run Robot Tests') {
            steps {
            bat "D:/robotframework/Scripts/activate.bat&&robot -d D:/ProgramWorkspace/DevTest-Notes/CI/jenkins/rf_results --include=login D:/ProgramWorkspace/DevTest-Notes/RobotFramework/PO_demo"
            sleep 1
            }
            
            post {
                always {
                    script {
                      step(
                            [
                              $class              : 'RobotPublisher',
                              outputPath          : 'rf_results',
                              outputFileName      : 'output.xml',
                              reportFileName      : 'report.html',
                              logFileName         : 'log.html',
                              disableArchiveOutput: false,
                              passThreshold       : 100,
                              unstableThreshold   : 80,
                            ]
                      )
                    }
                    emailext (
                        subject: '\'Build notification:${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}\'',
                        to: "zhiyo2016@163.com", 
                        body: '${FILE,path="email2.html"}',
                    )
                }
            }
        }
    }
}

preservation.

structure

Click [Build Now] manually, and the result is similar to that of a free style project.

jenkins platform will save the test report of each build.

--THE END--

It's not the wind, it's not the flag, it's the heart of benevolent people—— Sixth ancestor Huineng

Keywords: jenkins

Added by sathyan on Wed, 19 Jan 2022 07:21:33 +0200