Jenkins Node Plugin throwing npm-git install error - jenkins

I have jenkins installed on ubuntu and I installed the node Plugin and configured for the latest version of node with npm under the global tool configuration.
I am testing to run a pipeline where i will git clone and do a npm install and a npm test for my repo.
a sample is as below for my pipeline code:
pipeline {
environment{
registry = "xxxx"
registyCredential = 'harbor'
dockerImage = ''
}
agent any
tools{
nodejs "node"
}
stages {
stage('Git clone'){
steps{
git branch: 'development', url: 'https://github.com/leeadh/node-jenkins-app-example.git'
}
}
stage('Installing Node') {
steps {
sh 'npm install'
}
}
stage ('Conducting Unit test'){
steps{
sh 'npm test'
}
}
However, I keep getting a
976 verbose stack at ChildProcess.<anonymous> (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
976 verbose stack at ChildProcess.emit (events.js:193:13)
976 verbose stack at maybeClose (internal/child_process.js:999:16)
976 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5)
977 verbose pkgid playground#1.0.0
978 verbose cwd /var/lib/jenkins/workspace/Compile_Code_CI
979 verbose Linux 4.15.0-29-generic
980 verbose argv "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/node" "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/npm" "install"
981 verbose node v11.14.0
982 verbose npm v6.7.0
983 error file sh
984 error code ELIFECYCLE
985 error errno ENOENT
986 error syscall spawn
987 error playground#1.0.0 install: `npm-git install`
987 error spawn ENOENT
988 error Failed at the playground#1.0.0 install script.
988 error This is probably not a problem with npm. There is likely additional logging output above.
I tried to directly install node JS on to my ubuntu server but it still gives me the same error.
Any help?
PS: a strange thing is that I tried these same exact steps on another jenkins server (this one is running on docker) and it was working perfectly fine.

Related

eslint-config-react-app/jest': Cannot read property 'meta' of undefined

I create a project with create-react-app. I get this error when i run docker build frontend -t my-frontend . :
> frontend#0.1.0 build /app
> react-scripts build
Creating an optimized production build...
Failed to compile.
Failed to load plugin 'jest' declared in 'package.json » eslint-config-react-app/jest': Cannot read property 'meta' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-01-27T11_11_23_140Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1
how should i fix it? i tried npm install,npm install .,npm audit fix.
this is jest in my package.json :
{
...
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
...,
"web-vitals": "^1.0.1"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
...
}
and this is jest in my package.lock.json :
"eslint-plugin-jest": {
"version": "24.1.3",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.1.3.tgz",
"integrity": "...",
"requires": {
"#typescript-eslint/experimental-utils": "^4.0.1"
}
},
I also saw eslint-plugin-jest gives "ESLint stack trace: TypeError: Cannot read property 'meta' of undefined" that says: " This was a temporary issue in 22.6 up to 22.6.2" but my version is 24.1.3 .
Fixed by npm audit fix --force but before run, make sure it does not damage your project.
npm audit fix only modifies the dependencies that shouldn't cause problems based on SEMVER rules. The --force is a dangerious option because it upgrades the dependencies regardless of any rules. This can cause a dependency to go from version 1.2. 0 to version 2.3.
What did a npm audit fix --force change and how do you fix it?

Jenkins parallel stages - enoent ENOENT: no such file or directory

I am having a problem running some stages in parallel across different agents/nodes in Jenkins. I am creating stages dynamically from a list of available agents with the following code:
// Create empty collection to store parallel stages:
def parallelStages = [:]
// Define list of agents to be used for cypress parallel stages:
agents = [
"agent1",
"agent2",
...
]
// Add as many parallel stages as defined in agents list:
agents.eachWithIndex { label, index ->
parallelStages["Parallel Stage ${index + 1}"] = {
stage("Parallel Stage ${index + 1}") {
node(label) {
sh 'npm install --silent'
sh 'npm start & npx wait-on http://localhost:3000'
sh "npm run another_command"
}
}
}
}
Then I'm using these stages in a parallel block:
pipeline {
agent {
node {
label 'agent1'
}
}
stages {
stage('first-non-parallel-stage'){
steps {
sh 'npm install --silent'
sh 'npm run lint'
sh 'npm run build'
sh "npm run storybook:build"
sh 'npm run test -- --watchAll=false'
}
}
stage ('Parallel stuff'){
steps {
script {
parallel parallelStages
}
}
}
}
}
This is working. However, for the stage on agent1, I get the following errors in the Jenkins log:
+ npx wait-on http://localhost:3000
+ npm start
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/vine/workspace/tend-multibranch_jenkins-testing#3/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/vine/workspace/tend-multibranch_jenkins-testing#3/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
Some details that might be pertinent, but I'm not sure:
Prior to running the parallel stage, you can see I'm running a first-non-parallel-stage, on the agent that is having problems - could that be related? I don't have problems in first-non-parallel-stage, just in the parallel block on that agent. Shouldn't I be able to reuse agent1 in my parallel block after first-non-parallel-stage is done?
I don't get this issue when I use a repetetive verbose parallel block, i.e. instead of creating a function that populates a collection with stage blocks, I write them out by hand, like this:
parallel {
stage { ...stage_code }
stage { ...stage_code }
stage { ...stage_code }
}
But obviously this is verbose and doesn't lend to adding more nodes easily.
Why might this be happening?
The error occurs at the npm side as it is not able to find the file.May be would be a good idea to add npm init which creates the package.json file or delete the package-lock.json file after the non-parallel stage execution is done, so that when you enter the parallel block everything is clean. More details about this is available here : StackOverflow Answer
Thanks to comments from Noam Hemler and Altaf, I figured this out.
The crucial issue was that npm could indeed not find my project. What was being missed in some of the comments is the workspace should be cleaned before or after running the job, but the git repo scm must also be checked out fresh before trying to run any npm commands. I created this setup function:
def setup(){
// clean workspace and do a fresh checkout
deleteDir()
git credentialsId: 'id', url: 'url'
sh 'git checkout ' + env.Branch_Name
}
And now at the start of each stage:
// Add as many parallel stages as defined in agents list:
agents.eachWithIndex { label, index ->
parallelStages["Parallel Stage ${index + 1}"] = {
stage("Parallel Stage ${index + 1}") {
node(label) {
setup()
sh 'npm install --silent'
sh 'npm start & npx wait-on http://localhost:3000'
sh "npm run another_command"
}
}
}
}
And I'm using the setup function before any steps on any other agent too, so when a stage starts, it always cleans the space, pulls a fresh copy of the code, and begins from there. Seems to be working consistently.

How can I inject environment variables during the build process in Github CI/CD?

I am creating a blogsite with Gatsby and Contentful for learning purposes. I want to deploy my site to surge using Github actions. I am using gatsby-source-contentful plugin to get my content from Contentful at build time. The plugin requires spaceId and accessToken to access my Contenful space. During development at my local machine, I am providing these values to the plugin using environment variables saved in a .env file.
However, during the build process in Github actions, I am getting this error:
success open and validate gatsby-configs - 2.325s
error Invalid plugin options for "gatsby-source-contentful":
- "accessToken" is required
- "spaceId" is required
not finished load plugins - 1.002s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-contentful-blogsite#0.1.0 build: `tsc && gatsby build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-contentful-blogsite#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-02-18T17_53_11_281Z-debug.log
Error: Process completed with exit code 1.
Is there a way to tell Github actions about these environment variables (spaceId and accessToken) so that the gatsby-source-contentful plugin can be configured successfully?
Contentful DevRel here. 👋
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: `your_space_id`,
// Learn about environment variables: https://gatsby.dev/env-vars
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
},
},
],
}
In your gatsby config you can specify your environment variable such as above. Then in your GitHub repo you can define a secret and expose it as environment variable. You can find more information in the Github actions docs. Once you exposed the environment variable via the secret to the action, it should work fine.

Electron-builder: resource busy or locked. Failed to create installer

I have a little test electron app named hello world. I am trying to build it and generate a windows installer using electron-builder. My package.json is as follows.
{
"name": "hello-world",
"productName": "Hello World",
"version": "1.0.0",
"description": "Second attempt at an electron app",
"main": "main.js",
"dependencies": {},
"devDependencies": {
"electron": "^9.1.1",
"electron-builder": "^22.8.0"
},
"scripts": {
"start": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Computronics",
"license": "MIT",
"build": {
"appId": "com.hello.world",
"win": {
"target": "nsis"
}
}
}
When I run npm run dist it outputs this.
> hello-world#1.0.0 dist C:\Users\computronics\source\repos\electrontests\hello world
> electron-builder
• electron-builder version=22.8.0 os=10.0.18362
• loaded configuration file=package.json ("build" field)
• writing effective config file=dist\builder-effective-config.yaml
• packaging platform=win32 arch=x64 electron=9.1.2 appOutDir=dist\win-unpacked
⨯ EBUSY: resource busy or locked, rename 'C:\Users\computronics\source\repos\electrontests\hello world\dist\win-unpacked\electron.exe' -> 'C:\Users\computronics\source\repos\electrontests\hello world\dist\win-unpacked\Hello World.exe' stackTrace=Error: EBUSY: resource busy or locked, rename 'C:\Users\computronics\source\repos\electrontests\hello world\dist\win-unpacked\electron.exe' -> 'C:\Users\computronics\source\repos\electrontests\hello world\dist\win-unpacked\Hello World.exe'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-world#1.0.0 dist: `electron-builder`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-world#1.0.0 dist script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\computronics\AppData\Roaming\npm-cache\_logs\2020-07-31T19_00_12_846Z-debug.log
The contents of the log file is as follows:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dist'
1 verbose cli ]
2 info using npm#6.14.6
3 info using node#v12.18.3
4 verbose run-script [ 'predist', 'dist', 'postdist' ]
5 info lifecycle hello-world#1.0.0~predist: hello-world#1.0.0
6 info lifecycle hello-world#1.0.0~dist: hello-world#1.0.0
7 verbose lifecycle hello-world#1.0.0~dist: unsafe-perm in lifecycle true
8 verbose lifecycle hello-world#1.0.0~dist: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\computronics\source\repos\electrontests\hello world\node_modules\.bin;C:\Program Files\Microsoft VS Code\bin;C:\Windows\System32;C:\Program Files\Git\cmd;C:\Program Files\PowerShell\7-preview\preview;C:\ProgramData\chocolatey\bin;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\Users\computronics\.dotnet\tools;
9 verbose lifecycle hello-world#1.0.0~dist: CWD: C:\Users\computronics\source\repos\electrontests\hello world
10 silly lifecycle hello-world#1.0.0~dist: Args: [ '/d /s /c', 'electron-builder' ]
11 silly lifecycle hello-world#1.0.0~dist: Returned: code: 1 signal: null
12 info lifecycle hello-world#1.0.0~dist: Failed to exec dist script
13 verbose stack Error: hello-world#1.0.0 dist: `electron-builder`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid hello-world#1.0.0
15 verbose cwd C:\Users\computronics\source\repos\electrontests\hello world
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dist"
18 verbose node v12.18.3
19 verbose npm v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error hello-world#1.0.0 dist: `electron-builder`
22 error Exit status 1
23 error Failed at the hello-world#1.0.0 dist script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
After running npm run dist it creates a working .exe in dist called electron.exe. This launches into the simple hello world app.
I have tried deleting the node_modules folder and reinstalling the dependencies, forcefully cleaning the npm cache and trying different versions of electron-builder.
Other information
OS: Windows 10
npm version: 6.14.6
node version: 12.18.3
Thanks in advance for any help.
There may be more than one reason for this error. Here are the ways you can get rid out of this error.
Solution 1. Close the browser_broker process
Open up the Windows task manager, find the running process named either browser_broker.exe or Runtime Broker and stop the process. After stopping the process, try building the installer again and it will work.
Solution 2. Kill the Build Tools Process
Open task manager and kill the BuildTolls_Full.exe process. Then Go to C:\Users<User Name>.windows-build-tools and open build-tools-log.txt with a text-editor and append the given and save the file.
Variable: IsInstalled = 1

Test reports is missing in Jenkins

When my build failed - test report is missing in Jenkins. What do I do wrong?
This is part of my jenkinsfile:
node {
stage('Integration tests') {
git url: "https://$autotestsGitRepo", branch: 'develop',credentialsId: gitlabCredentialsId
sh 'chmod +x gradlew && ./gradlew clean test
step([$class: 'JUnitResultArchiver', testResults:'build/test-results/test/*.xml'])
}
}
This is my jenkins output:
5 tests completed, 5 failed
Task :test FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':test'.
There were failing tests. See the report at: file:///var/jenkins_home/workspace/test2/build/reports/tests/test/index.html
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1m 7s 4 actionable tasks: 4 executed [Pipeline] }
[Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of
Pipeline ERROR: script returned exit code 1 Finished: FAILURE

Resources