How Upload test results to alm by Jenkins groovy - jenkins

I am using HP ALM v 5.2 and uploaded my test results by making free style project from the gui now I want to add this step to pipeline, I searched on the internet and found this guide but gives me this error no known implementation of interface jenkins.tasks.SimpleBuildStep is named TestResultToALMUploade with to many exceptions
this is sample of code
junit testResults: '**/target/*-reports/TEST-*.xml', allowEmptyResults: true
step ([$class: 'TestResultToALMUploader',
almServerName: 'HP ALM Server', //almServerName
credentialsId: 'ALM-CREDENTIALS',
almDomain: 'ALMDomain', // almDomain
almProject: 'AlmProject', //almProject,
testingFramework: 'JUnit', //testingFramework
testingTool: '', //testingTool
almTestFolder: 'TestHPALM', //almTestFolder
almTestSetFolder: 'TestHPALM', //almTestSetFolder
almTimeout: '-1', //almTimeout
testingResultFile: "**/junitResult.xml", //testingResultFile
jenkinsServerUrl: '' //jenkinsServerUrl
])

I am not sure, if you already found the answer, but I managed to do it with adding this fragment to "publishers" section:
job {
parameters { ... }
steps { ... }
... // some other job configuration here ...
publishers {
archiveJunit("junitReport.xml")
testResultToALMUploader {
almServerName('HP ALM Server')
credentialsId('ALM-CREDENTIALS')
almDomain('ALMDomain')
almProject('AlmProject')
testingFramework('JUnit')
testingTool('')
almTestFolder('TestHPALM')
almTestSetFolder('TestHPALM')
almTimeout("")
testingResultFile("**/junitResult.xml")
jenkinsServerUrl('')
}
}
}

Related

"Ambiguous expression could be either a parameterless closure expression or an isolated open code block in jenkins parallel execution throws error

following code is throwing below error.
if(!SkipLanguageComponentTests){
^
WorkflowScript: : Groovy compilation error(s) in script. Error(s): "Ambiguous expression could be either a parameterless closure expression or an isolated open code block;
solution: Add an explicit closure parameter list,
script {
2 errors
`
def SkipLanguageComponentTests = false;
pipeline {
parameters {
booleanParam(name: 'SkipLanguageComponentTests', defaultValue: false, description: 'XYZ')
}
stages {
stage('Checkout Source') {
steps {
checkout scm
}
}
stage("Component & Language Tests"){
steps{
parallel (
"componentTestsTask":{
//component test start
dir("docker"){
sh script: "docker-compose -f blah blah\""
}
// some xyz step here
//component test ends here
},
"integrationTestTasks":{
// language test script starts
if(!SkipLanguageComponentTests){
//run lang test and publish report
} else {
echo "Skip Language Component Tests"
}
// language test script ends
}
)
}
}
}
`
I have tried as per the documentation https://www.jenkins.io/blog/2017/09/25/declarative-1/
I have tried this based on the answer mentioned in : Running stages in parallel with Jenkins workflow / pipeline
stage("Parallel") { steps { parallel ( "firstTask" : { //do some stuff }, "secondTask" : { // Do some other stuff in parallel } ) } }
Can someone help me to resolve this ?
Ok, here is the working version of your pipeline - with proper IF inside:
parameters {
booleanParam(name: 'SkipLanguageComponentTests', defaultValue: false, description: '')
}
agent { label 'master' }
stages {
stage("Component & Language Tests") {
parallel {
stage("componentTestsTask") {
steps {
//component test start
echo "docker"
// some xyz step here
//component test ends here
}
}
stage("integrationTestTasks") {
steps {
script {
// language test script starts
if (!params.SkipLanguageComponentTests) {
echo "not skipped"
//run lang test and publish report
} else {
echo "Skip Language Component Tests"
}
}
}
// language test script ends
}
}
}
}
}
This pipeline is not optimal, use below information to improve it.
Notes:
you are using declarative pipeline so I think it is better to stay with parallel section expressed in declarative way
help is here: Jenkins doc about parallel
there is scripted pipeline as well Jenkins doc about scripted pipeline
as I stated in original answer, you have to use params to refer to input parameter properly
if you are using code you have to enclose it in script section - this is like putting scripted pipeline inside declarative one
IF statement can also be done declaratively: Jenkins doc about WHEN
I recommend not to mix these 2 styles: so if you are using both for some good reason they should be separated from one another as much as possible for example by using function or library inside declarative pipeline - the goal is to have pipeline as clear and readable as possible
You are using input variable, so try to refer as it should be done for input in Jenkins:
if(!params.SkipLanguageComponentTests)

Jenkins User Acceptance code issue in Jenkins pipeline. How to implement multiple acceptance code in a single pipeline

I am trying to create a pipeline in which after my deployment, I will perform functional test and on the basis of that I want to conclude that whether I want to proceed further or not. I used Jenkins "input" feature. I am getting the message to proceed further, but when I click OK the nothing happened, It is stucked there only. And also after first Approval I have send approval step below, after that only I have to release the result.
I am not able to understand how to achieve as I am new to this. The pipeline code is mentioned below:
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "mvn"
jdk "jdk8"
}
stages {
stage('SCM Checkout') {
steps {
println "============= SCM Checkout =============="
}
}
stage('Code Inspection'){
steps {
println "============== SonarQube Scanning ======================="
}
}
stage('Build, Package & JUnit'){
steps {
println "============== Build, Package & JUnit ================"
}
}
stage('Deploy'){
steps {
println "============== Deploy and Split Traffic=================="
}
}
stage('Functional & Performance Test'){
steps {
println "=========== Functional and Performance Test ==============="
}
}
stage('A/B Testing'){
input {
message "Functional & Performance Test done. Should we continue?"
ok "OK"
}
steps {
println "=========== A/B Testing ==============="
}
}
stage('Release'){
input {
message "A/B Testing done. Should we continue?"
ok "OK"
}
steps {
println "========= Final Release =================="
}
}
}}
Is there any other way to achieve this? or who can I improve this code to achieve the desired result.
Use the input feature like this:
stage('Release'){
steps {
input message: "A/B Testing done. Should we continue?"
println "========= Final Release =================="
}
}
Make sure you also have the Pipeline: Input Step Plugin (a component of Pipeline Plugin) installed and activated:

How to add "single conditional steps" under build section using dsl script

I'm currently trying to develop a DSL script that can create a jenkins job with all required plugins and options.
I think I've almost completed all the section. But, I stuck up under build section where I've to include "conditional steps (single)" under Build.
Actually what I wanted is this
But, what I get is this
Here's the code that I used,
job('Sample_dev') {
steps {
conditionalSteps {
condition {
alwaysRun()
}
}
maven {
goals('install')
}
}
}
You have done few mistakes there:
Using multi-step DSL for achieving single step.
Pushed maven outside context like individual step.
Wrong DSL for Maven Step declaration.
Try following
job('Sample_dev')
{
steps{
singleConditionalBuilder{
condition{
alwaysRun()
}
buildStep {
maven{
targets('install')
name('')
pom('')
properties('')
jvmOptions('')
usePrivateRepository(false)
settings {
standard()
}
globalSettings {
standard()
}
injectBuildVariables(false)
}
}
runner {
fail()
}
}
}
}
The creator has deployed most on this url https://jenkinsci.github.io/job-dsl-plugin. But I would suggest you install in you local instance and access it via http://<your-jenkins-host>:<port> /plugin/job-dsl/api-viewer/index.html as Job DSL support auto generation so there is bright chance that plugin not listed above still has DSL support.

Visualize Jenkins pipeline or multibranch pipeline jobs

I have one Pipeline job for each component in my Jenkins 2.0. All of them
consist of many stages (build, UT, IT etc.), so they're working as a
pipeline for a component.
The components are depending on each other in a specified order, so I used "Build after other projects are built" (I also tried JobFanIn Plugin) to trigger these "mini-pipelines" after each other. This works like a pipeline of "mini pipelines"
I'd like to visualize the relationship between the jobs. For this purpose I've found 2 plugins:
Delivery Pipeline Plugin
Build Pipeline Plugin
Both introduce a new View type, but none of them supports the "Pipeline" or "Multibranch pipeline" job types (introduced in Jenkins 2.0), these jobs are not visible in the related dropdown list on the view config page.
How can I visualize the relation of these job types? Is there any other plugin which supports these types?
Thinking about this.
I don't think a visualisation of multi branch pipelines makes sense in the same way it would for a single branch build.
The reason is that each bench of a mb pipeline can have a different build configuration. Eg with master triggering a promotion job but branch doing something else or nothing.
Do the best one could do I think is trace an individual build number and it's links. Can't do it at the job level.
Jenkins blue ocean plugins give the rich view to visualize all types (parallel, sequential stages) view out of the box.
Let say if you have a pipeline like this
pipeline {
agent any;
stages {
stage('build') {
stages {
stage('compile') {
steps {
echo "steps for unitest"
}
}
stage('security scan') {
parallel {
stage('sonarqube') {
steps {
echo "steps for parallel sonarqube"
}
}
stage('blackduck') {
steps {
echo "steps for parallel blackduck"
}
}
}
}
stage('package') {
steps {
echo "steps for package"
}
}
}
}
stage('deployment') {
stages {
stage('dev') {
steps {
echo "Development"
}
}
stage('pp') {
when { branch 'master' }
steps {
echo "PreProduction"
}
}
stage('prod') {
when {
branch 'master'
beforeInput true
}
input {
message "Deploy to production?"
id "simple-input"
}
steps {
echo "Production"
}
}
}
}
}
}
It will visualize like this :
is this what you are looking for?
Note- it can customize. but this view is per build ..you can't create a dashboard from it and combine it all in one

Jenkins job dsl and MSTest integration

Jenkins Job DSL plugin is an extremely nice way to store CI config in repo and vary it from branch to branch.
The question is - is there a natural or close to natural way to run MSTest tests, parse results and display them.
Right now I do a powershell call, but that gives me only logs, not UI integration.
def testSomeProjectJob = job(testSomeProjectJobName) {
steps {
powerShell("& ${vstest} '${root}/SomeProject/SomeProject.Tests/bin/Debug/SomeProject.Tests.dll' ")
}
}
May be there is a publisher or a trick with templating, or some tips of writing a plugin to JOB DSL for that
UPD: final script template for MSTest and VSTest using #daspilker answer, jenkins xUnit Plugin and archiveXUnit
job('RunTests') {
steps {
// VSTEST
powerShell("& ${vstest} 'path/to/Tests.dll' /logger:trx ")
// Or MSBUILD
powerShell("& ${msbuild} /testcontainer:'path/to/Tests.dll' ")
}
publishers {
archiveXUnit {
msTest {
pattern('**/*.trx')
// deleteOutputFiles()
}
}
}
}
Using a PowerShell step is a good start. Install the xUnit Plugin to parse and display the results. It can parse all sorts of test results including MSTest. And you can use the DSL to configure the plugin.
Example:
job('example') {
steps {
powerShell('...')
}
publishers {
archiveXUnit {
msTest {
pattern('path/to/test/results')
}
}
}
}
Its for VSTest but I had to end up using the configure block to be able to use it in the DSL jobs.
static Closure useVsTest(List<String> dlls) {
return {
it / 'builders' << 'org.jenkinsci.plugins.vstest__runner.VsTestBuilder' {
vsTestName 'VS 14.0'
testFiles dlls.join('\n')
settings ''
testCaseFilter ''
enablecodecoverage false
useVsixExtensions true
platform 'x86'
otherPlatform ''
framework 'framework45'
otherFramework ''
logger 'trx'
otherLogger ''
cmdLineArgs '/TestAdapterPath:"."'
failBuild true
}
}
}

Resources