I am using jenkins with the pipeline plugin, the XUnitBuilder plugin and the stash notifier plugin. I have the problem that it reports the wrong build status. My pipeline:
pipeline {
agent none
stages {
stage('Build') {
steps {
parallel(
failFast: true,
'One': {
node( 'windows' ){
run tests ...
step([$class: 'XUnitBuilder',
thresholds: [
[$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '0', unstableThreshold: '0']
],
tools: [
[$class: 'CTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'Testing/**/Test.xml']
]
])
}
},
'Two': {
node( 'windows' ){
run tests ...
step([$class: 'XUnitBuilder',
thresholds: [
[$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '0', unstableThreshold: '0']
],
tools: [
[$class: 'CTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'Testing/**/Test.xml']
]
])
}
}
)
}
}
}
}
Problem: As soon as 'One' is finished, the XUnitBuilder sets the build result to success which is reported to stash and my pull request can be merged. This is obviously wrong since 'Two' may be not even started.
I need to
* prevent the XUnitPublisher from setting the build result if it is success or
* prevent stash from being notified before the whole pipeline finished
Sure, i could stash the test results and run the XUnitBuilder in a post section but this is getting quite complicated since my pipeline has several stages each with several parallel steps running tests.
Does anyone know hot to fix this?
Related
This is an example of my Jenkinsfile:
properties([
parameters([
booleanParam(defaultValue: false, name: 'BuildAll', description: ''),
// lots of params here, some of them are Active Choice Plugin params...
])
])
pipeline {
agent any
stages {
stage ('Initialize') {
// code...
}
}
}
Now, is it posslible to export those parameters (that are enclosed inside "properties" section) into shared library?
Jenkins shared library: https://www.jenkins.io/doc/book/pipeline/shared-libraries/
I have lots of params and many similar projects and I would like simply to define parameters on one place and include them everywhere (DRY).
create deriveJobParams.groovy in vars folder with following code in shared library project.
def call() {
properties([
parameters([
booleanParam(defaultValue: false, name: 'BuildAll', description: ''),
[$class: 'ChoiceParameter', choiceType: 'PT_CHECKBOX',
description: 'Choose environment category.',
name: 'ENVIRONMENT',
script: [
$class: 'GroovyScript',
script: [sandbox: true, script: 'return ["QA", "DEV", "PROD"]']
]
]
])
])
}
In job Jenkinsfile, import the share library and call deriveJobParams()
#Library('my-library#branch or tag') _
// call deriveJobParams at beginning
deriveJobParams()
pipeline {
stages {
}
}
I have started porting my existing Jenkins job to Jenkins Pipeline.
When it came to port the Scan for compiler warning in Post-build action, I started getting issues.
First I tried to port PC-Lint. Used the following code
stage ('Warnings pclint') {
steps {
timeout(time: 5, unit: 'MINUTES') {
sh 'npm run lint:ci'
step([$class: 'WarningsPublisher',
parserConfigurations: [[
parserName: 'PC-Lint',
pattern: 'pmd.xml'
]],
unstableTotalAll: '0',
usePreviousBuildAsReference: true
])
}
}
}
But it didn't work. What is wrong in this ?
Is there any other way to do this ?
After searching a lot finally I got a working syntax.
step([$class: 'WarningsPublisher',
consoleParsers: [[parserName:'PC-Lint']],
defaultEncoding: '',
excludePattern: '',
healthy: '',
includePattern: '',
messagesPattern: '',
unHealthy: '',
useStableBuildAsReference: true
])
It is good to have this in the post build section of the Pipeline
This guy seems to have the same problem.
Here is what I am doing:
stage('Test') {
steps {
bat "\"${tool 'VSTestRunner'}\" %WORKSPACE%\\MyApp\\bin\\Debug\\MyApp.dll /logger:trx & exit 0"
// The test publish is responsible for decided whether the test stage failed
step([$class : 'XUnitPublisher',
testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [
[$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '1', unstableNewThreshold: '', unstableThreshold: ''],
[$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']
],
tools : [[$class: 'MSTestJunitHudsonTestType',
deleteOutputFiles: true,
failIfNotNew: false,
pattern: "TestResults\\*.trx",
skipNoTestFiles: false,
stopProcessingIfError: true
]]
])
}
}
If the tests fail the pipeline still continues.
I would like to be able to control whether the pipeline continues or not via the xunit settings. Is there a more elegant way of doing this than this:
if (currentBuild.result.equals("FAILURE")) {
throw "Test results did not pass thresholds"
}
Also, what does "stopProcessingIfError" do? I thought it would stop the pipeline if the error threshold was exceeded but it doesn't. Is there a param to the xunit service that does that?
FAILED, SUCCESS, and UNSTABLE are jenkins build status and not exit status. exit status should come from the process that is being executed. So, your solution is to set an exit 1 (or something non-zero), if the test fails. You batch step seem to be setting an exit 0. Check for the ERRORLEVEL as you seem to be in windows, and if its non-zero, break out from the pipeline by forcing an `exit 1'
note: it can be anything but should not be 0. (i am referring to the 1 in exit code)
I have a pipeline job that uses the p4jenkins plugin to poll a perforce stream for changes. The polling itself does seem to work, but when polling, it keeps finding the same changelists as new over and over again.
The polling interval is set as:
H/2 * * * * # short interval for testing purposes
My Jenkins pipeline checkout step (using a shared global library):
def call(body) {
def config=[:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
//checkout from p4 based on provided stream
checkout([
changelog: true,
poll: true,
scm: [
$class: 'PerforceScm',
credential: 'my_p4_service_creds',
populate : [
$class: 'AutoCleanImpl',
delete: false,
modtime: false,
parallel: [
enable: false,
minbytes: '1024',
minfiles: '1',
path: '/my/path/to/local/p4/bin/p4',
threads: '4'],
pin '',
quiet: false,
replace: true
],
workspace: [
$class: 'StreamWorkspaceImpl',
charset: 'none',
format: 'jenkins-${NODE_NAME}-${JOB_NAME}',
pinHost: false,
streamName:
"//${config.streamDepot}/${config.stream}"
]
]
])
}
At first, I thought it maybe was picking up the same changes over and over because they were pending changelists, but I've also tried making sure the stream only contains changelists that can be synced directly to a workspace.
Any ideas?
I want to integrate our Polymer test build process into Jenkins CI/CD pipeline using polymer-cli. I want to automate this steps to build our web-components test cases. At the moment, I am doing this manually by executing "polymer test" on the terminal. I also want the automated process to provide the reports that indicate failed test cases. Please provide step if you have implemented this in your CI/CD pipeline.
We have the following working setup for this case, using Jenkins2 Pipelines:
node{
....
stage('build'){
testresult = bat returnStatus: true, script: 'polymer test --plugin xunit-reporter -l chrome'
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '5', failureThreshold: '10', unstableNewThreshold: '2', unstableThreshold: '5'], [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']], tools: [[$class: 'XUnitDotNetTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'TEST-wct.xml', skipNoTestFiles: false, stopProcessingIfError: true]]])
if (testresult != 0) {
currentBuild.result = "UNSTABLE"
echo "ALERT: Some Unittests failed, see log above."
}
}
....
}
The testresult is written by the wct-plugin https://github.com/garcus/wct-xunit-reporter to "/TEST-wct.xml".
The XUnit Builder step is configured as such, that it picks that file up and creates the testresult page. You can lookup the syntax for that in the Jenkins Pipeline syntax help page.
See also How to display the XUnit test output on Jenkins
and JUnit formatted test output