Robot Framework Browser Library screenshots are not nested in log although being copied by RobotPublisher in Jenkins Pipeline - jenkins

Jenkins 2.386
Pipeline plugin 590.v6a_d052e5a_a_b_5
Robot Framework plugin 3.3.0
Python3.9.2
robotframework 6.0.2
robotframework-assertion-engine 1.0.0
robotframework-browser 15.1.0
robotframework-pythonlibcore 4.0.0
Screenshots are not nested in log
Robot Publisher copies results to specific build
Using "otherFiles" option copies PNG images and Browser Library directories structure
Clicking the icon of missing image in Robot log redirects to screenshot properly.
I work on Jenkins master node - I don't use slaves.
Here is my Jenkinsfile:
pipeline {
agent any
stages {
stage('Test') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'robot -d results Scripts/My_Test_Suite.robot'
}
}
}
stage('Results') {
steps {
step([
$class: 'RobotPublisher',
outputPath: 'results',
outputFileName: '*.xml',
otherFiles: '**/*.png',
])
}
}
}
}
Update:
Before I faced described problem I configured CSP just like here: https://stackoverflow.com/a/37524992/6639428.
That means I used following configuration and according to https://content-security-policy.com/img-src/ it should work, but it doesn't...
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' ;")

Related

Creating parser with percentiles:'0,50,90,100,' filterRegex:null Cannot detect file type because of error: Failed to copy jmeter-newtest.csv

Build is failing in execute jmeter stage, I'm attaching both error and jmeter build stage below
could some hlep me in this
Jenkins pipelnie :
stage('Execute Jmeter') {
when {
expression { return pipelineStages.contains("JMETER-TEst") }
}
steps{
sh 'pwd'
}
post{
always{
dir("/target/jmeter/results/"){
sh 'pwd'
perfReport 'jmeter-newtest.csv'
}
}
}
}
Error :
Creating parser with percentiles:'0,50,90,100,' filterRegex:null
Cannot detect file type because of error: Failed to copy /target/jmeter/results/jmeter-newtest.csv to /data/jenkins/jobs/project-service/branches/adding-jmeter-build-step/builds/19/temp/jmeter-newtest.csv
I don't think you have /target/jmeter/results/, it looks like an absolute path and I believe you need the relative path to the Jenkins workspace folder
So my expectation is that if you change /target/jmeter/results/ to target/jmeter/results/ your script should start working as expected.
I also don't think you need to change the working directory, Performance Plugin can scan for result file(s) using Fileset syntax so you can just do something like:
perfReport '**/*jmeter-newtest.csv'
More information: How to Use the Jenkins Performance Plugin

How to setup a Jenkins pipeline for postman tests

Postman is used as a popular testing tool for API testing, you can write bunch of unit tests using Postman and execute them as a part of your build process to perform unit testing. The following covers the Jenkins integration of Postman tests.
In order to do that you should have
Exported Postman tests as a collection
Make the APIs available at run time when the tests are performed. (Using docker or by creating a separate build pipeline.)
Node module newman can be used to execute Postman collections. Refer the following Package.json file. Here we are executing the postman collection inside the unit_tests folder using newman, also newman dependency is defined.
package.json
{
"name": "postman-newman-jenkins",
"version": "1.0.0",
"description": "My Test Project",
"directories": {
"tests": "tests"
},
"scripts": {
"newman-tests": "newman run unit_tests/my-collection.postman_collection.json --reporters cli,junit --reporter-junit-export newman.xml --insecure"
},
"author": "Test Author",
"dependencies": {
"newman": "^3.5.2"
}
}
The following is the content of the Jenkinsfile. We are using NPM to install the dependencies and execute tests.
Jenkinsfile
pipeline {
agent { label 'LinuxSlave' }
stages {
stage ('Checkout') {
steps {
checkout scm
}
}
stage('Test'){
steps {
sh 'npm install'
sh 'npm run newman-tests'
junit 'newman.xml'
}
}
}
}
you can avoid installing newman on the machine (slave/ master) and use docker
example pipeline script:
pipeline {
agent any stages {
stage('Test') {
steps {
sh 'docker run -t postman/newman_ubuntu1404 run https://www.getpostman.com/collections/8a0c9bc08f062d12dcda'
}
}
}
}
more info on docker & newman here

environmentVariables() not working for Jenkins Job DSL and Pipeline Jobs

We use Jenkins Job DSL for our CI setup. Since we are using a special command only available in the traditional Jenkinsfile syntax, we need to use a pipeline job.
Inside of the pipeline job we check out our project from Git. We are using the pipeline job for multiple projects, so we want to inject the git url into the pipeline script.
This is a short version of our script generating the pipeline job:
def createPipelineJob(def jobName, def gitUrl) {
pipelineJob(jobName) {
environmentVariables(GIT_URL: gitUrl)
definition {
cps {
script('''
node {
sh 'env | sort'
}
''')
sandbox(true)
}
}
}
}
This creates the following XML config:
<flow-definition>
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<EnvInjectJobProperty>
<info>
<propertiesContent>GIT_URL=my-git.url</propertiesContent>
<loadFilesFromMaster>false</loadFilesFromMaster>
</info>
<on>true</on>
<keepJenkinsSystemVariables>true</keepJenkinsSystemVariables>
<keepBuildVariables>true</keepBuildVariables>
<overrideBuildParameters>false</overrideBuildParameters>
<contributors/>
</EnvInjectJobProperty>
</properties>
<triggers/>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition">
<script>
node { sh 'env | sort' }
</script>
<sandbox>true</sandbox>
</definition>
</flow-definition>
But if i run this, the GIT_URL environment variable is not listed (other environment variables are). But if i instead create the pipeline job manually with this setup, the GIT_URL environment variable is printed just fine. Creating the job manually pretty much creates the same xml configuration:
<flow-definition plugin="workflow-job#2.15">
<actions>
<io.jenkins.blueocean.service.embedded.BlueOceanUrlAction plugin="blueocean-rest-impl#1.3.1">
<blueOceanUrlObject class="io.jenkins.blueocean.service.embedded.BlueOceanUrlObjectImpl">
<mappedUrl>blue/organizations/jenkins/test-jobname</mappedUrl>
<modelObject class="flow-definition" reference="../../../.."/>
</blueOceanUrlObject>
</io.jenkins.blueocean.service.embedded.BlueOceanUrlAction>
</actions>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<com.sonyericsson.rebuild.RebuildSettings plugin="rebuild#1.27">
<autoRebuild>false</autoRebuild>
<rebuildDisabled>false</rebuildDisabled>
</com.sonyericsson.rebuild.RebuildSettings>
<EnvInjectJobProperty plugin="envinject#2.1.5">
<info>
<propertiesContent>GIT_URL=my-git.url</propertiesContent>
<secureGroovyScript plugin="script-security#1.35">
<script/>
<sandbox>false</sandbox>
</secureGroovyScript>
<loadFilesFromMaster>false</loadFilesFromMaster>
</info>
<on>true</on>
<keepJenkinsSystemVariables>true</keepJenkinsSystemVariables>
<keepBuildVariables>true</keepBuildVariables>
<overrideBuildParameters>false</overrideBuildParameters>
</EnvInjectJobProperty>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers/>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps#2.41">
<script>
node { sh 'env | sort' }
</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>
We are pretty lost because we are new to jenkins and this problem is holding us for days now.
Edit:
The job is generated on the jenkins master node but executed on a slave node
Jenkins 2.37.3
Environment Injector Plugin 2.1.5
Pipeline 2.5
This is more of a comment than an answer, but I modified and tested your DSL code and it works fine.
I created a DSL job using the script:
def createPipelineJob(def jobName, def gitUrl) {
pipelineJob(jobName) {
environmentVariables(GIT_URL: gitUrl)
definition {
cps {
script('''
node {
sh "echo $GIT_URL"
}
''')
sandbox(true)
}
}
}
}
createPipelineJob('new-job-2','my-git.url')
The resulting pipeline job has the same XML as the one you posted (minus the shell script), and building the pipeline job prints the value of GIT_URL.
[new-job-1] Running shell script
+ echo my-git.url
my-git.url
My recommendation:
If the short version you posted (or maybe try mine) doesn't work, I would try to see if upgrading Jenkins or the plugins makes any difference.
If the short version you posted or mine does work, maybe post the full version, perhaps there's an error there.
As it turns out the Environment Injector Plugin was not installed successfully, therefore the script did not run properly. So all i had to do was to restart Jenkins and everything worked just fine. Special thanks to Javier Garcés ensuring me that my script was indeed correct.

How does one run allure plugin in jenkins pipeline?

I'm building pipeline/jenkins-based CI for several projects and want to store allure results just as it would be done in regular build with fast access icon. Is it possible from pipeline?
We were failed to use Allure Jenkins Plugin in pipeline. It seems that it supports job-dsl-plugin only. So... just add stage where you generate report using Allure CLI and publish report as regular HTML report. Icon for it will be available on job and build screen.
UPDATE
Allure v2 has supported pipeline - see documentation.
stage('reports') {
steps {
script {
allure([
includeProperties: false,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'target/allure-results']]
])
}
}
}
install the allure plugin for your jenkins.
Go to your pipleline build configuration. click on pipeline syntax, select allure reports, fill-in the required fields, click generate syntax, it will give you the required code to be added to your existing groovy scripts
I am now using Allure report with Jenkins pipeline
You have to perform some additional configuration steps:
_1. Jenkins master must start with the following options as described in http://wiki.qatools.ru/display/AL/Allure+Jenkins+Plugin
(sample docker-compose.yaml)
version: '2'
services:
jenkins.master:
image: jenkins
# ...
environment:
JAVA_OPTS: "-Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';\" -Djenkins.model.DirectoryBrowserSupport.CSP=\"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';\""
_2. HTML Publisher plugin installed from jenkins plugin center
_3. Allure report is generated by maven, sample pom.xml is here https://github.com/ludenus/mobile_test_poc/blob/master/pom.xml
$ mvn -Dmaven.test.failure.ignore=true site
_4. Allure report is published by HTML publisher
stage('Publish') {
echo 'Publish Allure report'
publishHTML(
target: [
allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'target/site/allure-maven-plugin',
reportFiles : 'index.html',
reportName : "Allure Report"
]
)
}

Jenkins Pipeline: How to archive artifacts when the build fails?

When our browser based tests fail, we take a screenshot of the browser window to better illustrate the problem. However, I don't understand how to archive them in my pipeline, because the pipeline stops after the failure. Same for the junit.xml, I'd also like to use it in error cases.
I've checked, the screenshots are generated and stored correctly.
My definition looks like this (irrelevant things mostly trimmed):
node {
stage('Build docker container') {
checkout([$class: 'GitSCM', ...])
sh "docker build -t webapp ."
}
stage('test build') {
sh "mkdir -p rspec screenshots"
sh "docker run -v /var/jenkins_home/workspace/webapp/rspec/junit.xml:/myapp/junit.xml -v /var/jenkins_home/workspace/webapp/screenshots:/myapp/tmp/capybara -v webapp bundle exec rspec"
}
stage('Results') {
junit 'rspec/junit*.xml'
archive 'screenshots/*'
}
}
You can use simple Java try/catch to avoid pipeline failure on test failure, or Jenkins catchError like this :
node {
catchError {
// Tests that might fail...
}
// Archive your tests artifacts
}
From here, you can use the post section in your pipeline:
pipeline {
agent any
stages {
stage('Build') {
...
}
stage('Test') {
...
}
}
post {
always {
archive 'build/libs/**/*.jar'
}
}
}

Resources