jenkins-library
jenkins-library copied to clipboard
No files found for pattern '*lint.xml'. Configuration error?
I'm trying to run an ESLint pipeline on Jenkins with the SAP Project Piper. To run a linting, I configured the following Jenkins file:
@Library('piper-lib-os') _
node() {
stage('LINT_POC') {
npmExecuteLint script: this
}
}
According to the npmExecuteLint documentation, that should be enough, but when I run this code on Jenkins, I get the following error:
[LINT] [-ERROR-] No files found for pattern '*lint.xml'. Configuration error?
As far as I know, ESLint uses eslintrc.json as a config file, so how should I generate an *lint.xml file? And where should I put this file?
Hi!
- ESLint will be used by default in case package.json doesn't contain script with name
ci-lint(the name by default). This name may be overwritten withrunScriptparameter. - *lint.xml - it's lint checkstyle output. If
ci-lintscript exists then make sure it uses something like thischeckstyle -o [YOUR_LINT_FILE_NAME]lint.xml. If noci-lintprovided, then step should automatically generate something like thisDIGIT_defaultlint.xmlor justdefaultlint.xml.
In accordance with above info, please, double check the following: config for npmExecuteLint in .pipeline/config.yml, "scripts" section in package.json.
If everything is OK but you still see this issue - please ping us here again.
@raman-susla-epam, thanks for details.
In my case I've configured:
- Jenkins → Build Configuration → Mode → Script Path →
jenkins_pipeline_script:
@Library('piper-lib-os') _
node() {
stage('LINT_POC') {
npmExecuteLint script: this
}
}
- In
package.jsonI tried several configurations:
Variant 1:
"scripts": {
"ci-lint": "node ./node_modules/eslint/bin/eslint.js -f checkstyle src > eslint.xml"
}
Variant 2:
"scripts": {
"ci-lint": "./node_modules/eslint/bin/eslint.js -f checkstyle src > eslint.xml"
}
Variant 3:
"scripts": {
"ci-lint": "node checkstyle -o 2022lint.xml"
}
Variant 4:
"scripts": {
"ci-lint": "checkstyle -o 2022lint.xml"
}
Variant 5:
"scripts": {
"lint": "node eslint -c .eslintrc"
}
Variant 6:
"scripts": {
"lint": "eslint -c .eslintrc"
}
None of these variants doesn't work for me and I constantly get:
No files found for pattern
*lint.xml. Configuration error?
Is there something I miss to configure?
try something like this:
npx eslint . -f checkstyle -o ./2022lint.xml
I've tried:
"scripts": {
"ci-lint": "npx eslint . -f checkstyle -o ./2022lint.xml"
}
but the same error.
Information Messages:
Searching for all files in
/var/apphome/%instance%/.jenkins/workspace/ESLint_Pipeline_masterthat match the pattern*lint.xml
Can it be the problem of permissions on Jenkins's side?
Can it be the problem of permissions on Jenkins's side?
it can, if the same script generate xml locally.
OK, but is it possible to get an output right into console (e.g. into Jenkins's Lint Warnings), without creating and writing into *lint.xml?
jenkins uses this xml later here https://www.jenkins.io/doc/pipeline/steps/warnings-ng/#recordissues-record-compiler-warnings-and-static-analysis-results
recordIssues blameDisabled: true,
enabledForFailure: true,
aggregatingResults: false,
tool: script.checkStyle(id: "lint", name: "Lint", pattern: "*lint.xml")
Hi @KevinHudemann, do you have any thoughts?
OK, but is it possible to get an output right into console (e.g. into Jenkins's Lint Warnings), without creating and writing into
*lint.xml?
Hi @pubmikeb,
this should be possible if you instead use the step npmExecuteScripts to execute the script you have defined in the package.json.
With your example pipeline, e.g.:
@Library('piper-lib-os') _
node() {
stage('LINT_POC') {
npmExecuteScripts script: this, runScripts: ['ci-lint']
}
}
I hope this helps.
Hey @KevinHudemann,
thanks for your reply, I've tried to replace npmExecuteLint with npmExecuteScripts to run my npm script and get:
An error occurred in the library step:
npmExecuteScripts:
hudson.AbortException: script returned exit code 1
Since npmExecuteScripts contains only one script, the problem happens in:
"scripts": {
"ci-lint": "node eslint -c .eslintrc -o 2022lint.xml"
}
Hi @pubmikeb,
this seems to be a problem in your ci-lint script. I guess it's because you're missing the parameter for which files or directories ESLint should be executed. In addition, I guess you cannot use node eslint. Instead, either use npx eslint or node ./node_modules/eslint/bin/eslint.js
To execute ESLint in the current folder, e.g.,:
"scripts": {
- "ci-lint": "node eslint -c .eslintrc -o 2022lint.xml"
+ "ci-lint": "npx eslint -c .eslintrc -o 2022lint.xml ."
}
In general, I would recommend to first write and test the script locally and when it works locally, use and test it in the pipeline.
@KevinHudemann, bingo, with your proposal I can generate an XML linting report locally in SAP BAS!
Now, I need to realize why xml file is not created on Jenkins side.
Thanks for your assistance.
@KevinHudemann, is there any benefit of using ci-lint over npmExecuteLint?
Thank you for your contribution! This issue is stale because it has been open 60 days with no activity. In order to keep it open, please remove stale label or add a comment within the next 10 days. If you need a Piper team member to remove the stale label make sure to add @SAP/jenkins-library-team to your comment.
Hi @pubmikeb apologies for the delayed response.
I am not sure if I understand the question. ci-lint is a npm script defined in the package.json. npmExecuteLint is a convenience step in the library which can execute ESLint with a default config or a config you provide with your project.
If you have specific requirements there are two options.
- Provide an ESLint config and define the script
ci-lintin yourpackage.json. - Use or extend the step
npmExecuteScriptsand configure it accordingly.
I hope this helps to give you more insights about the intended use. Please let me know if you have any additional questions. Best Regards, Kevin
@KevinHudemann, thanks for your assistance, I've already solved my issue. The problem was with the path configuration to the Docker image.
Steps for integration ESLint into Jenkins Pipeline using SAP Project Piper:
- In package.json,
scriptssection:
"pretest": "npx eslint **/*.js -c .eslintrc -f checkstyle -o report.eslint.xml ."
- In Jenkins Pipeline YAML:
steps:
npmExecuteLint:
dockerImage: %PATH_TO_DOCKER_IMAGE%
runScript: pretest
stages:
Build:
npmExecuteLint:
dockerImage: %PATH_TO_DOCKER_IMAGE%
runScript: pretest
When using npx, it's important to properly configure the proxy, otherwise npx couldn't retrieve the wanted library's code.