jenkins-library icon indicating copy to clipboard operation
jenkins-library copied to clipboard

No files found for pattern '*lint.xml'. Configuration error?

Open pubmikeb opened this issue 3 years ago • 13 comments

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?

pubmikeb avatar Apr 20 '22 13:04 pubmikeb

Hi!

  1. 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 with runScript parameter.
  2. *lint.xml - it's lint checkstyle output. If ci-lint script exists then make sure it uses something like this checkstyle -o [YOUR_LINT_FILE_NAME]lint.xml. If no ci-lint provided, then step should automatically generate something like this DIGIT_defaultlint.xml or just defaultlint.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 avatar May 31 '22 16:05 raman-susla-epam

@raman-susla-epam, thanks for details.

In my case I've configured:

  1. Jenkins → Build Configuration → Mode → Script Path → jenkins_pipeline_script:
@Library('piper-lib-os') _

node() {
	stage('LINT_POC') {
		npmExecuteLint script: this
	}
}
  1. In package.json I 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?

pubmikeb avatar Jun 01 '22 07:06 pubmikeb

try something like this:

npx eslint . -f checkstyle -o ./2022lint.xml

raman-susla-epam avatar Jun 01 '22 09:06 raman-susla-epam

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_master that match the pattern *lint.xml

Can it be the problem of permissions on Jenkins's side?

pubmikeb avatar Jun 01 '22 10:06 pubmikeb

Can it be the problem of permissions on Jenkins's side?

it can, if the same script generate xml locally.

raman-susla-epam avatar Jun 01 '22 10:06 raman-susla-epam

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?

pubmikeb avatar Jun 01 '22 10:06 pubmikeb

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")

raman-susla-epam avatar Jun 01 '22 10:06 raman-susla-epam

Hi @KevinHudemann, do you have any thoughts?

raman-susla-epam avatar Jun 01 '22 11:06 raman-susla-epam

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.

KevinHudemann avatar Jun 01 '22 12:06 KevinHudemann

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"
}

pubmikeb avatar Jun 01 '22 15:06 pubmikeb

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 avatar Jun 01 '22 15:06 KevinHudemann

@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.

pubmikeb avatar Jun 01 '22 16:06 pubmikeb

@KevinHudemann, is there any benefit of using ci-lint over npmExecuteLint?

pubmikeb avatar Jul 27 '22 19:07 pubmikeb

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.

github-actions[bot] avatar Sep 26 '22 00:09 github-actions[bot]

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.

  1. Provide an ESLint config and define the script ci-lint in your package.json.
  2. Use or extend the step npmExecuteScripts and 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 avatar Sep 26 '22 05:09 KevinHudemann

@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:

  1. In package.json, scripts section:
"pretest": "npx eslint **/*.js -c .eslintrc -f checkstyle -o report.eslint.xml ."
  1. 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.

pubmikeb avatar Sep 26 '22 10:09 pubmikeb