Jenkins: Cannot build nodejs project in different versions of nodejs in single build - node.js

Lately, I'm trying to build a nodejs project using nodejs 6, 7 and 8 via Jenkins.
I have installed Pipeline NPM Integration Plugin. In Jenkins > Global Tool Configuration, I have added the different versions of nodejs.
But when I build the project, it gets only build in nodejs version 6. This is the content of my Jenkinsfile.
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
nodejs('Chill') {
sh 'node --version'
sh 'npm --version'
sh 'yarn --version'
sh 'yarn'
sh 'yarn build'
}
}
}
stage('Test') {
steps {
nodejs('Chill') {
sh 'yarn test'
}
}
}
stage('Deploy') {
steps {
nodejs('Chill') {
}
}
}
}
}
This the log file of the build.
Started by user Sumit Rai
Obtained Jenkinsfile from git https://github.com/srekcahrai/chill.git
[Pipeline] node
Running on 10.10.0.143 in /home/jenkins-client/jenkins/workspace/Chill SCM
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/srekcahrai/chill.git # timeout=10
Fetching upstream changes from https://github.com/srekcahrai/chill.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/srekcahrai/chill.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 52fb0d17de1a3a2f25292443ee6038d10e22953e (refs/remotes/origin/master)
Commit message: "Added Deploy stage"
> git config core.sparsecheckout # timeout=10
> git checkout -f 52fb0d17de1a3a2f25292443ee6038d10e22953e
> git rev-list 52fb0d17de1a3a2f25292443ee6038d10e22953e # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] nodejs
[Pipeline] {
[Pipeline] sh
[Chill SCM] Running shell script
+ node --version
v6.11.2
[Pipeline] sh
[Chill SCM] Running shell script
+ npm --version
3.10.10
[Pipeline] sh
[Chill SCM] Running shell script
+ yarn --version
0.27.5
[Pipeline] sh
[Chill SCM] Running shell script
+ yarn
yarn install v0.27.5
[1/4] Resolving packages...
success Already up-to-date.
$ npm run build
> chill-cli#1.0.0-alpha.2 build /home/jenkins-client/jenkins/workspace/Chill SCM
> run-s lint clean babel
> chill-cli#1.0.0-alpha.2 lint /home/jenkins-client/jenkins/workspace/Chill SCM
> eslint src test
> chill-cli#1.0.0-alpha.2 clean /home/jenkins-client/jenkins/workspace/Chill SCM
> rimraf dist/
> chill-cli#1.0.0-alpha.2 babel /home/jenkins-client/jenkins/workspace/Chill SCM
> babel src/ -d dist/
src/cli/index.js -> dist/cli/index.js
src/common/messages.js -> dist/common/messages.js
src/config/config.js -> dist/config/config.js
src/config/default.config.js -> dist/config/default.config.js
src/index.js -> dist/index.js
src/migrations/20170515111050_create_status_logs_table.js -> dist/migrations/20170515111050_create_status_logs_table.js
src/models/StatusLog.js -> dist/models/StatusLog.js
src/monitoring/Monitor.js -> dist/monitoring/Monitor.js
src/monitoring/eventListener.js -> dist/monitoring/eventListener.js
src/monitoring/init.js -> dist/monitoring/init.js
src/services/email.js -> dist/services/email.js
src/services/events.js -> dist/services/events.js
src/services/hipchat.js -> dist/services/hipchat.js
src/services/notifier.js -> dist/services/notifier.js
src/services/persistence.js -> dist/services/persistence.js
src/services/slack.js -> dist/services/slack.js
src/services/status.js -> dist/services/status.js
src/services/twilio.js -> dist/services/twilio.js
src/services/websocket.js -> dist/services/websocket.js
src/utils/db.js -> dist/utils/db.js
src/utils/emailRenderer.js -> dist/utils/emailRenderer.js
src/utils/http.js -> dist/utils/http.js
src/utils/logger.js -> dist/utils/logger.js
src/utils/string.js -> dist/utils/string.js
src/utils/websocketServer.js -> dist/utils/websocketServer.js
Done in 11.21s.
[Pipeline] sh
[Chill SCM] Running shell script
+ yarn build
yarn build v0.27.5
$ run-s lint clean babel
> chill-cli#1.0.0-alpha.2 lint /home/jenkins-client/jenkins/workspace/Chill SCM
> eslint src test
> chill-cli#1.0.0-alpha.2 clean /home/jenkins-client/jenkins/workspace/Chill SCM
> rimraf dist/
> chill-cli#1.0.0-alpha.2 babel /home/jenkins-client/jenkins/workspace/Chill SCM
> babel src/ -d dist/
src/cli/index.js -> dist/cli/index.js
src/common/messages.js -> dist/common/messages.js
src/config/config.js -> dist/config/config.js
src/config/default.config.js -> dist/config/default.config.js
src/index.js -> dist/index.js
src/migrations/20170515111050_create_status_logs_table.js -> dist/migrations/20170515111050_create_status_logs_table.js
src/models/StatusLog.js -> dist/models/StatusLog.js
src/monitoring/Monitor.js -> dist/monitoring/Monitor.js
src/monitoring/eventListener.js -> dist/monitoring/eventListener.js
src/monitoring/init.js -> dist/monitoring/init.js
src/services/email.js -> dist/services/email.js
src/services/events.js -> dist/services/events.js
src/services/hipchat.js -> dist/services/hipchat.js
src/services/notifier.js -> dist/services/notifier.js
src/services/persistence.js -> dist/services/persistence.js
src/services/slack.js -> dist/services/slack.js
src/services/status.js -> dist/services/status.js
src/services/twilio.js -> dist/services/twilio.js
src/services/websocket.js -> dist/services/websocket.js
src/utils/db.js -> dist/utils/db.js
src/utils/emailRenderer.js -> dist/utils/emailRenderer.js
src/utils/http.js -> dist/utils/http.js
src/utils/logger.js -> dist/utils/logger.js
src/utils/string.js -> dist/utils/string.js
src/utils/websocketServer.js -> dist/utils/websocketServer.js
Done in 9.35s.
[Pipeline] }
[Pipeline] // nodejs
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] nodejs
[Pipeline] {
[Pipeline] sh
[Chill SCM] Running shell script
+ yarn test
yarn test v0.27.5
$ NODE_ENV=test mocha
Chill 1.0.0-alpha.2 - Test SuiteLoading config file: chill.test.yml
cli
--version
chill 1.0.0-alpha.2
✓ should print the chill cli version (1477ms)
--help
Usage: chill [options]
Options:
-h, --help Show help [boolean]
-c, --config Configuration file path.
-V, --version Show version number [boolean]
✓ should print the chill usage help string (1468ms)
config.get
✓ should return the previously resolved config from the cache.
config.resolve
Loading config file: function () { [native code] }
✓ should return default configuration even if the config file is empty.
Loading config file: function () { [native code] }
✓ should merge and return both the config loaded from file and the default ones.
Loading config file: function () { [native code] }
✓ should return the resolved config that overrides the default values if same keys are found.
Loading config file: Glens
✓ should put the resolved config in the cache.
Monitor.handleStatusChange
✓ should trigger the EVENT_STATUS_CHANGED event.
Monitor.isStatusDifferent
✓ should return true if status is different.
✓ should return false if status is same.
Monitor.start
✓ should trigger the EVENT_MONITORING_STARTED event.
email.isEnabled
✓ should return true if email notification is enabled.
✓ should return false if email notification is not enabled.
Unhandled rejection AssertionError: expected 'Investment Account' to equal 'digital'
at EventEmitter.<anonymous> (/home/jenkins-client/jenkins/workspace/Chill SCM/test/monitoring/Monitor.handleStatusChange.test.js:24:14)
at Object.invoke (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/sinon/lib/sinon/behavior.js:140:32)
at EventEmitter.functionStub (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/sinon/lib/sinon/stub.js:83:53)
at Function.invoke (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/sinon/lib/sinon/spy.js:194:51)
at EventEmitter.proxy (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/sinon/lib/sinon/spy.js:97:22)
at emitOne (events.js:96:13)
at EventEmitter.emit (events.js:188:7)
at Object.trigger (/home/jenkins-client/jenkins/workspace/Chill SCM/src/services/events.js:16:11)
at Monitor.handleStatusChange (/home/jenkins-client/jenkins/workspace/Chill SCM/src/monitoring/Monitor.js:69:12)
at Monitor._callee2$ (/home/jenkins-client/jenkins/workspace/Chill SCM/src/monitoring/Monitor.js:47:12)
at tryCatch (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/regenerator-runtime/runtime.js:65:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/regenerator-runtime/runtime.js:303:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/regenerator-runtime/runtime.js:117:21)
at step (/home/jenkins-client/jenkins/workspace/Chill SCM/src/monitoring/Monitor.js:31:191)
at /home/jenkins-client/jenkins/workspace/Chill SCM/src/monitoring/Monitor.js:31:361
at tryCatcher (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/jenkins-client/jenkins/workspace/Chill SCM/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
email.getClient
✓ should create a nodemailer transport with provided configurations
email.notify
✓ should send email notification with correct parameters.
hipchat.isEnabled
✓ should return true if hipchat notification is enabled.
✓ should return false if hipchat notification is not enabled.
hipchat.notify
✓ should send the notification payload to the hipchat API endpoint.
✓ should log error if it fails to send notification to hipchat.
notifier.notify
✓ should notify if slack is enabled
✓ should not notify if slack is not enabled
persistence.persist
✓ should persist status log to database.
✓ should log an error if it cannot persist to database.
persistence.getLastStatus
✓ should get last status of service from database.
✓ should return null if it cannot get last status of service from database.
✓ should log an error if it cannot fetch from database.
slack.isEnabled
✓ should return true if slack notification is enabled.
✓ should return false if slack notification is not enabled.
slack.notify
✓ should send the notification payload to the slack API endpoint.
✓ should log error if it fails to send notification to slack.
status.getCheckInterval
✓ should return maximum interval if status is up.
✓ should return minimum interval if status is down.
center
✓ would return the text centered with left-padding slightly less than the right-padding if width is even and text length is odd.
✓ would return the text centered with left-padding slightly less than the right-padding if width is odd and text length is even.
✓ should return the text centered with equal padding on both sides if the width and text length are both odd numbers.
✓ should return the text centered with equal padding on both sides if the width and text length are both even numbers.
✓ should return the same text if the width is less than or equal to the text length.
✓ should return the centered text with custom fillchar too.
twilio.isEnabled
✓ should return true if twilio notification is enabled.
✓ should return false if twilio notification is not enabled
twilio.notify
✓ should send notification from twilio with correct params
✓ should log error when twilio fails to send the message
websocket.isEnabled
✓ should return true if websocket notification is enabled.
✓ should return false if websocket notification is not enabled.
websocket.init
✓ should initialize websocket server if websocket is enabled.
✓ should not initialize websocket server if websocket is disabled.
websocket.notify
✓ should broadcast to all clients.
47 passing (3s)
Done in 6.85s.
[Pipeline] }
[Pipeline] // nodejs
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] nodejs
[Pipeline] {
[Pipeline] }
[Pipeline] // nodejs
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
In travis, the same process is done by
language: node_js
node_js:
- "8"
- "7"
- "6"
before_script:
- yarn build
script:
- yarn test
I am confused whether it is a bug in the plugin because the plugin allows to multiple version of nodejs, or should I mention them manually in Jenkinsfile.

I think that the tools section is missing. here is an example with mvn.
pipeline {
agent { label 'your-label' }
options {
timestamps()
timeout(time: 15, unit: 'MINUTES')
}
tools {
maven 'Maven-3.3.9'
}
stages { ......

Related

groovy.lang.MissingPropertyException: No such property: GIT_PASSWORD for class: groovy.lang.Binding

I have checked all the topics on the same mistake, tried everything, and yet I was unable to find anything to help me solving my issue.
my code builds a docker container, starts a flask application and run a python script, run tests and then should merge Master. The code is the following :
pipeline {
agent any
stages {
stage('Master merging'){
steps{
script{
passwordVariable = 'password'
usernameVariable = 'unsername'
// Variables for input
if(env.BRANCH_NAME == 'features'||env.BRANCH_NAME == 'main'){
sh 'git checkout origin/features'
sh 'git pull'
sh 'git remote update'
sh 'git fetch'
sh 'git checkout origin/main'
sh 'git merge origin/features'
withCredentials([usernamePassword(credentialsId : 'GitHub', passwordVariable:'GIT_PASSWORD', usernameVariable:'GIT_USERNAME')]){
sh "git push http://${GIT_USERNAME}:${GIT_PASSWORD}#github.com/Username/Repo.git"
}
}}
}
}
}
}
when I arrive to stage('master merging'), I have the following mistake
Masking supported pattern matches of $GIT_PASSWORD
[Pipeline] {
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (container shutdown)
Stage "container shutdown" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: GIT_PASSWORD for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
Thanks a lot in advance for your help :)
I have an answer :)
Prerequisites : create a credential on Manage jenkins -> Manage credentials -> jenkins -> Global credentials (unrestricted) -> username with password. Inquire github username as username and Personal access token as password. ID is up to you.
Code :
stage('Master merging'){
steps{
script{
// Variables for input
if(env.BRANCH_NAME == 'features'||env.BRANCH_NAME == 'main'){
sh 'git checkout features'
sh 'git pull'
sh 'git remote update'
sh 'git fetch'
sh 'git checkout origin/main'
sh 'git merge features'
sh "git config user.email \"GITHUB EMAIL\""
sh "git config user.name \"GITHUB USERNAME\""
withCredentials([gitUsernamePassword(credentialsId:'ID you inquired in credentials')]) {
sh 'git push https://github.com/Username/Repo.git'
}
}
}
}
}

How to hide parameters such as APIKey from Jenkins pipeline console output

How can I hide certain parameters or **** them when I execute scripts inside stage.
The command that is producing the output which I want to hide is:
sh "./wsagent_execute.sh -s -apiKey ${WHITESOURCE_API_KEY} -projectToken ${WHITESOURCE_PROJECT_TOKEN} -C ${configPath} -d ${directoryPath} -logLevel info"
The parameters I want to hide are -apiKey and -projectToken. How can I do it?
If you get your credentials from a vault, you can use Mask Passwords plugin. It does not state that it supports Pipelines but actually it does.
pipeline {
agent any
stages {
stage('doing something') {
steps {
script {
def current_nano = "1616407597607795668"
sh label: "Now you see it", script: "echo ${current_nano}"
maskPasswords(varPasswordPairs: [[password: current_nano, var: 'IGNORE']]) {
sh label: "Now you don't", script: "echo ${current_nano}"
}
}
}
}
}
}
Output:
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/
[Pipeline] {
[Pipeline] stage
[Pipeline] { (doing something)
[Pipeline] script
[Pipeline] {
[Pipeline] sh (Now you see it)
+ echo 1616407597607795668
1616407597607795668
[Pipeline] maskPasswords
[Pipeline] {
[Pipeline] sh (Now you don't)
+ echo ********
********
[Pipeline] }
[Pipeline] // maskPasswords
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Are these keys calculated in the pipeline or are they statics?
You can try to use it like credentials in Jenkins and you don't see their values in the log.
If you use a secret define in Jenkins credential, Jenkins will automatically mask that for you and in the log, it will show as ****
let's say you have defined your apiKey in jenkins credential with Id: apikey. Than you can use that on your pipeline like below example.
more details can be found here
node() {
withCredentials([string(credentialsId: 'apikey', variable: 'TOKEN')]) {
sh "./wsagent_execute.sh -s -apiKey $TOKEN -projectToken ${WHITESOURCE_PROJECT_TOKEN} -C ${configPath} -d ${directoryPath} -logLevel info"
}
}
If you are not happy with that use mask password or something similar plugins

How to debug jenkins pipeline failure while Jenkins killed process

The goal: build an Angular app
My Jenkins setup: master >> slave >> node docker
I'm trying to build an Angular app on the slave via docker, The installation works well and the code runs on the docker node image.
node works well - relevant log
+ node -v
v14.4.0
[Pipeline] sh
+ npm install -g #angular/cli
npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
/home/jenkins/jenkins_slave/workspace/build_app/.npm-global/bin/ng -> /home/jenkins/jenkins_slave/workspace/build_app/.npm-global/lib/node_modules/#angular/cli/bin/ng
> #angular/cli#9.1.7 postinstall /home/jenkins/jenkins_slave/workspace/build_app/.npm-global/lib/node_modules/#angular/cli
> node ./bin/postinstall/script.js
+ #angular/cli#9.1.7
updated 1 package in 10.171s
[Pipeline] sh
+ npm install
audited 1049 packages in 13.505s
found 1935 vulnerabilities (1587 low, 3 moderate, 345 high)
run `npm audit fix` to fix them, or `npm audit` for details
The problem is when I'm trying to build the app with `ng build', the angular start the build but Jenkins kills the process without throw any error
My code
stage('Deploy') {
steps {
script {
try {
echo 'Deploying....'
sh ".npm-global/bin/ng build"
} catch (err) {
echo err
currentBuild.result == 'FAILURE'
}
}
}
}
Edit: log after insert build code to try-catch
+ .npm-global/bin/ng build
Killed
[Pipeline] echo
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
$ docker stop --time=1 26fc42fc32db015d53d64735350ce16690d1fec8086708dd10391701d1c427fe
$ docker rm -f 26fc42fc32db015d53d64735350ce16690d1fec8086708dd10391701d1c427fe
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.ClassCastException: org.jenkinsci.plugins.workflow.steps.EchoStep.message expects class java.lang.String but received class hudson.AbortException
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:492)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:269)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor304.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.lang.IllegalArgumentException: Could not instantiate {message=hudson.AbortException: script returned exit code 137} for org.jenkinsci.plugins.workflow.steps.EchoStep
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:269)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor304.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:52)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor153.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
There is no log for from Npm/Node/Angular
So my questions is
How to debug Jenkins pipeline failures and how to get more details?
How to see the ng build command output?
Edit 2
As #MattSchuchard suggested in the comment, I was trying to use err.toString() / err.getMessage() / err.getStackTrace() methods, but the resutlt error is the same.
I think that the error comes because Jenkins killed the process and not because an error occurred in my process.

Getting permission denied when trying to run a shell script on jenkins pipeline

I'm trying to set a Jenkins pipeline to build an Ionic app inside a Linux server (ec2 instance on amazon services) My first stage inside the jenkinsfile is to run npm install, but it returns permission denied.
I've tried setting permissions to the folder using:
chmod 777 /home/ec2-user/.nvm/versions/node/v10.16.0/bin
I've also tried adding the Jenkins user to the group that also has permissions. none of these seemed to work.
This is my Jenkinsfile
pipeline {
agent any
environment {
PATH='/usr/local/bin:/usr/bin:/bin'
}
stages {
stage('NPM Setup') {
steps { sh '/home/ec2-user/.nvm/versions/node/v10.16.0/bin/npm install' }
}
stage('Android Build') {
steps {
sh 'ionic cordova build android --release'
}
}
stage('APK Sign') {
steps {
echo "Sign Android APK Action"
}
}
stage('Zip APK') {
steps {
echo "Zip the APK Action"
}
}
}
}
I get this output
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (NPM Setup)
[Pipeline] sh
+ /home/ec2-user/.nvm/versions/node/v10.16.0/bin/npm install
/var/lib/jenkins/workspace/p-ionic4_borderapp_ionic4_master#tmp/durable-9b0ecc49/script.sh: line 1: /home/ec2-user/.nvm/versions/node/v10.16.0/bin/npm: Permission denied

Could not resolve org.nodejs : Local build error

I have a Angular-App forked from another repository where they manage all their builds in a pipeline.
I wanted to build that in my local system (laptop) and push the built-app in to the hosting server.
This is their build.gradle
node {
version = "9.4.0"
npmVersion = "5.6.0"
download = true
}
task cleanProd(type: Delete) {
delete "dist"
}
task testProd(type: NodeTask, dependsOn: npmInstall) {
script = file("${projectDir}/node_modules/#angular/cli/bin/ng")
args = ["test", "--browsers", "PhantomJS", "--watch=false", "--singleRun=true"]
}
task assembleProd(type: NodeTask, dependsOn: ['npmInstall', 'testProd']) {
script = file("${projectDir}/node_modules/#angular/cli/bin/ng")
args = ["build", "--prod", "--vendor-chunk=true"]
}
task copyDist(type: Copy) {
from "dist/"
into "dist/fancy-ui-${project.version}"
}
task buildProd(dependsOn: [assembleProd])
I executed the command gradlew cleanProd buildProd copyDist and I am stuck with the below exception
Build Version = build-713-ge359ca9
:cleanProd UP-TO-DATE
:nodeSetup FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nodeSetup'.
> Could not resolve all dependencies for configuration 'detachedConfiguration1'.
> Could not resolve org.nodejs:node:9.4.0.
Required by:
:portal-ui:build-713-ge359ca9
> Could not resolve org.nodejs:node:9.4.0.
> Could not get resource 'https://nodejs.org/dist/v9.4.0/ivy.xml'.
> Could not GET 'https://nodejs.org/dist/v9.4.0/ivy.xml'.
> nodejs.org
I have all the necessary HTTP-Proxies and there is no issue with connectivity as such .. Just that this resource https://nodejs.org/dist/v9.4.0/ivy.xml is not getting loaded .. but the same code and configuration built fine in the Jenkins server
I had the same problem with node 10.14.1.
There is a workaround that solves the problem:
repositories.whenObjectAdded {
if (it instanceof IvyArtifactRepository) {
metadataSources {
artifact()
}
}
}
Extracted from https://github.com/srs/gradle-node-plugin/issues/301

Resources