Unknown lifecycle phase "test-ci'" - jenkins

I am trying to run my tests in jenkins pipelines.
but i got this error
Unknown lifecycle phase "test-ci'". You must specify a valid lifecycle
phase or a goal in the format : or
:[:]:.
Available lifecycle phases are: validate, initialize,
generate-sources, process-sources, generate-resources,
process-resources, compile, process-classes, generate-test-sources,
process-test-sources, generate-test-resources, process-test-resources,
test-compile, process-test-classes, test, prepare-package, package,
pre-integration-test, integration-test, post-integration-test, verify,
install, deploy, pre-clean, clean, post-clean, pre-site, site,
post-site, site-deploy. -> please how could i fix it ?
here is the full error:
C:\Users\ASUS\Documents\formation\jenkins\home\workspace\RDV>./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm -Dfrontend.npm.arguments='run test-ci'
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< ma.portnet.gestionrdvs:gestion-rd-vs >----------------
[INFO] Building Gestion RD Vs 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.543 s
[INFO] Finished at: 2022-04-11T00:04:08+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "test-ci'". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
Aucun fichier de rapport de test n'a été trouvé. Erreur de configuration?
here is my jenkins file
#!/usr/bin/env groovy
node {
stage('checkout') {
checkout scm
}
stage('check java') {
bat "java -version"
}
stage('clean') {
bat "./mvnw -ntp clean -P-webapp"
}
stage('nohttp') {
bat "./mvnw -ntp checkstyle:check"
}
stage('install tools') {
bat "./mvnw -ntp com.github.eirslett:frontend-maven-plugin:install-node-and-npm#install-node-and-npm"
}
stage('npm install') {
bat "./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm"
}
stage('backend tests') {
try {
bat "./mvnw -ntp verify -P-webapp"
} catch(err) {
throw err
} finally {
junit '**/target/surefire-reports/TEST-*.xml,**/target/failsafe-reports/TEST-*.xml'
}
}
stage('frontend tests') {
try {
bat "./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm -Dfrontend.npm.arguments='run test-ci'"
} catch(err) {
throw err
} finally {
junit '**/target/test-results/TESTS-results-jest.xml'
}
}
stage('packaging') {
bat "./mvnw -ntp verify -P-webapp -Pprod -DskipTests"
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}

Related

Analyzing code with SonarQube from Jenkins pipeline while using docker container Sonnar Scanner

I want to perform SonarQube analysis of a git repository code and I want to use SonarScanner from Docker Container, not from within Jenkins Configuration.
I've tried to create this pipeline:
pipeline {
agent { docker { image 'emeraldsquad/sonar-scanner:latest' } }
stages {
stage('build && SonarQube analysis') {
steps {
withSonarQubeEnv('sonar.tools.devops.****') {
sh 'sonar-scanner \\ -Dsonar.projectKey=myProject \\ -Dsonar.sources=./src \\'
}
}
}
stage("Quality Gate") {
steps {
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
// Requires SonarScanner for Jenkins 2.7+
waitForQualityGate abortPipeline: true
}
}
}
}
}
The build fails on stage build && SonarQube analysis, with build output:
Injecting SonarQube environment variables using the configuration: sonar.tools.devops.*****
[Pipeline] {
[Pipeline] sh
+ sonar-scanner ' -Dsonar.projectKey=myProject' ' -Dsonar.sources=./src' '\'
ERROR: Unrecognized option: -Dsonar.sources=./src
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO: -D,--define <arg> Define property
INFO: -h,--help Display help information
INFO: -v,--version Display version information
INFO: -X,--debug Produce execution debug output
I would try to remove double backslashes between the arguments:
sh 'sonar-scanner -Dsonar.projectKey=myProject -Dsonar.sources=./src'
The backslashes escape spaces which won't be trucated by the shell and are added to the argument's name.

Why do failing tests cause entire Jenkins build to be marked as "UNSTABLE" by Allure plugin?

I have set up Jenkins test jobs that will run Cucumber tests and want my jobs to always be successful up until a certain threshold (which I am controlling). The Allure plugin is always marking my builds as "UNSTABLE" when I have failed tests but I do not want my builds to be unstable. How can I change this behavior with allure?
I have tried setting
<testFailureIgnore>true</testFailureIgnore>
in pom.xml which is allowing the Maven Build to be successful. However, I am manually checking the Allure results in prometheusData.txt that is generated and failing/passing builds based off that result.
I want to be able to set Success/Failure status based off the 80% threshold. I am not aware of any thresholding that exists with Allure right now which is why I had to do it this way
Pipeline script
def testsInfo = readFile "${env.WORKSPACE}/allure-report/export/prometheusData.txt"
def passingTests = 0;
def totalTests = 0
def lineText = ''
def lineNum = 0
while(lineText != 'found'){
findText = testsInfo.split("\n")[lineNum]
if(findText.contains('launch_status_passed')){
passingTests = findText.split(' ')[1].toInteger()
}
if(findText.contains('launch_retries_run')){
totalTests = findText.split(' ')[1].toInteger()
lineText='found'
}
lineNum++
}
echo 'passing tests: ' + passingTests + ' total tests: ' + totalTests
percentSuccess = ((passingTests / totalTests) * 100).toString().split('\\.')[0]
echo 'Percent of tests that passed: ' + percentSuccess
if(build_ok && (percentSuccess.toInteger() > 80)) {
currentBuild.result = 'SUCCESS'
echo 'build OK'
} else {
currentBuild.result = 'FAILURE'
echo 'build bad'
}
Jenkins output
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] expected:<true> but was:<false>
[ERROR] expected:<[1].00> but was:<[2].00>
[ERROR] expected:<1.[0]0> but was:<1.[4]0>
[INFO]
[ERROR] Tests run: 90, Failures: 3, Errors: 0, Skipped: 0
[INFO]
[ERROR] There are test failures.
[INFO] -----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------
[INFO] Total time: 04:05 min
[INFO] Finished at: 2019-06-24T17:31:36Z
[INFO] Final Memory: 33M/1349M
[INFO] -----------------------------------------------------------------
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.
[Pipeline] // stage
[Pipeline] readFile
[Pipeline] echo
passing tests: 96 total tests: 100
[Pipeline] echo
Percent of tests that passed: 96
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: UNSTABLE

invoke gradle in jenkins pipeline

I am trying to use gradle in jenkins pipeline. The build fails with error "Task clean not found in root project 'pipe1'"
Installed jenkins on centos
pipeline {
agent any
stages{
stage('source') {
steps {
git 'https://github.com/javahometech/my-app.git'
}
}
stage('compile') {
tools {
gradle 'gradle3'
}
steps {
sh 'gradle clean compile'
}
}
}
}
build fails with error
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
What went wrong:
Task 'clean' not found in

Stop jenkins pipeline stage from failing when there are no changes to push to GitHub

Help me in stopping a stage failing, failing the further stages and as a result, the whole build. The problem is down to a stage where there are no changes to commit to GitHub. The code is below:
pipeline {
agent { label 'master' }
environment {
// 'This value is exported to all commands in this stage'
blah
blah..
blah...
}
stages {
stage('Check Environment') {
steps {
sh "echo 'Build_Id: ' $BUILD_ID"
sh "echo 'Job_Name: ' $JOB_NAME"
sh "echo 'Build_Name: ' $BUILD_NAME"
sh "echo 'Current Branch Name: ' $BRANCH"
}
}
stage('Checkout Source Code') {
steps {
git branch: 'develop', url: 'git#github.com:something-some/otherthing.git'
}
}
stage('Snapshot - Version Upgrade') {
environment {
VERSION = readMavenPom().getVersion()
}
steps {
script {
sh '''
#!/bin/bash -xe
echo $VERSION
mvn build-helper:parse-version versions:set versions:commit '-DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}'
git status
git add .
MVN_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
git commit -m "Jenkins version upgrade - ${MVN_VERSION}"
git push --set-upstream origin $BRANCH
'''
}
}
}
stage('Test Release - Deploy Packages To Artifactory') {
steps {
script {
sh '''
blah
more blah..
'''
}
}
}
When there are no changes in stage('Snapshot - Version Upgrade') - The stage is failing, how do I stop it from failing, please help.
Here is the snippet from the log where it fails:
[INFO]
[INFO] --- versions-maven-plugin:2.5:commit (default-cli) # Integrityv1 ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Some project Parent ................................ SUCCESS [ 0.010 s]
[INFO] Child Proj1......................................... SUCCESS [ 0.007 s]
[INFO] Child Proj2......................................... SUCCESS [ 0.007 s]
[INFO] Child Proj3......................................... SUCCESS [ 0.007 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:07 min
[INFO] Finished at: 2018-07-13T13:25:37+01:00
[INFO] Final Memory: 27M/304M
[INFO] ------------------------------------------------------------------------
+ git status
On branch develop
nothing to commit, working directory clean
+ git add .
+ mvn -q -Dexec.executable=echo -Dexec.args=${project.version} --non- recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec
+ MVN_VERSION=1.0.2
+ git commit -m Jenkins version upgrade - 1.0.2
On branch develop
nothing to commit, working directory clean
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test Release - Deploy Packages To Artifactory)
Stage "Test Release - Deploy Packages To Artifactory" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Publish to Windows Share)
Stage "Publish to Windows Share" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Delete Target)
Stage "Delete Target" skipped due to earlier failure(s)
You could only perform commit and push if there are changes:
if [ ! -z "$(git status --porcelain)" ]; then
git commit -m "Jenkins version upgrade - ${MVN_VERSION}"
git push --set-upstream origin $BRANCH
fi
See documentation on git-status if you are not familiar with --porcelain.

How to distinguish failed tests from syntax error in jenkins pipeline

I have this Jenkinsfile:
node{
stage ('Checkout')
{
checkout scm
}
stage ('Build')
{
try {
sh '''
mvn clean -B org.jacoco:jacoco-maven-plugin:prepare-agent install
'''
} catch (err) {
// do nothing
currentBuild.result = 'FAILED'
} finally {
//step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1,
thresholds: [
[$class: 'FailedThreshold', unstableThreshold: '2'],
[$class: 'SkippedThreshold', unstableThreshold: '']],
tools: [
[$class: 'JUnitType', deleteOutputFiles: false, failIfNotNew: false, pattern: '**/target/surefire-reports/TEST-*.xml', skipNoTestFiles: true, stopProcessingIfError: false]]
])
}
}
}
I want to mark the build as UNSTABLE when : some tests are failed using threshold of xUnit plugin, and I want to mark it FAILED if there is any error in the code like syntax error.
The problem here is that catch is executed in both situations: code error and test failure. How can I configure the Jenkinsfile to make the difference ?
After running a build that has 3 test failures ( threshold is 2 ), I expected the build to be UNSTABLE but it turned to FAILED:
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing JUnit
[xUnit] [INFO] - [JUnit] - 1 test report file(s) were found with the pattern '**/target/surefire-reports/TEST-*.xml' relative to '/var/lib/jenkins/workspace/jenkins-failure_master-EHKMAGGDJWHA7FNGHQYY2VJNJHBX2RXI3XJY4NU5EB2PYT4ERTZQ' for the testing framework 'JUnit'.
[xUnit] [INFO] - Check 'Failed Tests' threshold.
[xUnit] [INFO] - The total number of tests for this category exceeds the specified 'unstable' threshold value.
[xUnit] [INFO] - Setting the build status to FAILURE
[xUnit] [INFO] - Stopping recording.
New case: I commented the line currentBuild.result = 'FAILED' and I added a syntax error in the test class. The build is successed even with the COMPILATION ERROR and it skipped the tests:
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing JUnit
[xUnit] [INFO] - [JUnit] - No test report file(s) were found with the pattern '**/target/surefire-reports/TEST-*.xml' relative to '/var/lib/jenkins/workspace/jenkins-failure_master-EHKMAGGDJWHA7FNGHQYY2VJNJHBX2RXI3XJY4NU5EB2PYT4ERTZQ' for the testing framework 'JUnit'. Did you enter a pattern relative to the correct directory? Did you generate the result report(s) for 'JUnit'?
[xUnit] [WARNING] - No test reports found for the metric 'JUnit' with the resolved pattern '**/target/surefire-reports/TEST-*.xml'.
[xUnit] [INFO] - Skipping the metric tool processing.
[xUnit] [INFO] - There are errors when processing test results.
[xUnit] [INFO] - Skipping tests recording.
From Reporting test results and storing artifacts (declarative pipeline):
pipeline {
agent { docker "java" }
stages {
stage("build") {
steps {
sh 'mvn clean install -Dmaven.test.failure.ignore=true'
}
}
}
post {
always {
archive "target/**/*"
junit 'target/surefire-reports/*.xml'
}
}
}
Use -Dmaven.test.failure.ignore=true to prevent failing the build on test failures. The junit step then collects the test results and marks the build as unstable.
This is also how it is done under the covers when using a non-pipeline Maven job, see JENKINS-24655.

Resources