Jenkins pipeline does not run strapi start command? - jenkins

I wrote a jenkins pipeline that check out the git repo code and do the npm install command and strapi start command . But when it execute strapi start it shows error like "(node:12501) UnhandledPromiseRejectionWarning: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'dev_user'#'localhost' (using password: YES)" . I does not know why it happens but it successfully completed the npm install command. Any help. This is stage I am getting error.
stage('Install all dependencies and start'){
echo 'INFO - Starting installing the package.json file'
sh 'npm install'
sh 'strapi start'
}
Thank you

Related

Jenkins cannot find sh script in git repo

In my git repo I have build script located in /Src/build.sh. I have set up simple Jenkins file which runs this script:
node {
stage 'Checkout'
checkout scm
stage 'Build'
sh "chmod +x ./Src/build.sh"
sh "./Src/build.sh"
}
Execution of chmod seems to be successfull, but running build.sh gives me this error:
+ ./Src/build.sh
/var/lib/jenkins/workspace/wrksp#tmp/durable-d3f345e7/script.sh: 1:
/var/lib/jenkins/workspace/wrksp#tmp/durable-d3f345e7/script.sh: ./Src/build.sh: not found
I have no idea what is wrong?

Jenkins - groovy script returned exit code 126

I got a very simple Groovy script in Jenkins running in pipeline
For this code:
sh 'chmod +x gradlew'
sh './gradlew build --info'
I'm getting this error:
[Pipeline] sh
+ ./gradlew build --info
/var/jenkins_home/workspace/Pipeline with Gradle#tmp/durable-646d54ad/script.sh: line 1: ./gradlew: Permission denied
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 126
Finished: FAILURE
What am I missing here?
Looks like it does not have permission to run gradlew from your error message.
line 1: ./gradlew: Permission denied
You can do the following:
SSH into the jenkins machine
Switch to jenkins user
sudo su jenkins -
Check the permissions on the file gradlew using the command
ls -l /var/lib/jenkins/workspace/Pipeline with Gradle
Run the connand ./gradlew build --info from terminal and make sure it works before you run the job again
I use declarative pipelines using groovy and it works fine. I have grails installed on the machine and jenkins user can run the command. I use:
sh './gradlew dependencies && ./gradlew assemble && find ./ -name "*.war"'
Please add a comment if you have any more questions...

npm not found error in jenkins pipeline job

I have a pipeline job, where I give npm install. The script goes like :
node {
stage('Configure repo') {
sh 'npm install'
}
}
I am getting error
/mnt/jenkins/workspace/project/proj/dura/script.sh: 2: /mnt/jenkins/workspace/project/proj/dura/script.sh: /usr/local/npm: not found
Even I tried giving sh '/usr/local/npm install' But still the same.
Please help
Run this command:
sudo -u jenkins which npm
You should see /usr/bin/npm or some other path to npm as the result. if not, run this command:
sudo apt install npm
This often happens when you don't specifically install npm after installing node. Because node installs an instance of npm in your home, which other user's will not have access to. Then you feel you already installed npm but the fact is, you didn't!

"./gradlew: Permission denied" when deploying a jhipster 5.1.0 project on Gitlab-CI

I am using jhipster 5.1.0, I used "jhipster ci-cd" in order to generate the .gitlab-ci.yml file.
I am running Gitlab and Gitlab-CI on a private Ubuntu 18.04LTS server in my company. I configured the Gitlab Runner to execute the builds with docker.
My .gitlab-ci.yml file is as follows (I did not modify it much):
image: jhipster/jhipster:v5.1.0
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .gradle/wrapper
- .gradle/caches
stages:
- build
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- ./gradlew yarn_install -PnodeInstall --no-daemon
gradle-build:
stage: build
script:
- ./gradlew compileJava -x check -PnodeInstall --no-daemon
- ./gradlew test -PnodeInstall --no-daemon
- ./gradlew yarn_test -PnodeInstall --no-daemon
- ./gradlew bootJar -Pprod -x check -PnodeInstall --no-daemon
artifacts:
paths:
- build/libs/*.jar
# Uncomment following to expire the artifacts after defined period, https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts-expire_in
# expire_in: 90 day
Here is the output of the gitlab-ci runner:
...
Successfully extracted cache
$ export GRADLE_USER_HOME=`pwd`/.gradle
$ ./gradlew compileJava -x check -PnodeInstall --no-daemon
/bin/bash: line 60: ./gradlew: Permission denied
ERROR: Job failed: exit code 1
As the problem seems obvious, I tried to add " - chmod +x gradlew", before the ".gradlew" call in the "before_script" section. I thought it would be a good idea, because it was generated by the "jhipster ci-cd" command before 5.1.0, but not anymore. No success: Gitlab-CI output became as follows:
...
Successfully extracted cache
$ export GRADLE_USER_HOME=`pwd`/.gradle
$ chmod +x gradlew
chmod: changing permissions of 'gradlew': Operation not permitted
ERROR: Job failed: exit code 1
So I tried to switch to the docker image "openjdk:8" instead of "jhipster/jhipster:v5.1.0", in the .gitlab-ci.yml file. Much better, gradle runs the "yarn install" command, but it stops at some point, because that container does not contain "libpng-dev" (which was added recently into the jhipster container, no luck !):
...
[5/5] Building fresh packages...
error An unexpected error occurred:
"/builds/epigone/exportCCN/node_modules/pngquant-bin: Command failed.
Exit code: 1
Command: sh
Arguments: -c node lib/install.js
Directory: /builds/epigone/exportCCN/node_modules/pngquant-bin
Output:
⚠ The `/builds/epigone/exportCCN/node_modules/pngquant-bin/vendor/pngquant`
binary doesn't seem to work correctly
⚠ pngquant pre-build test failed
ℹ compiling from source
✔ pngquant pre-build test passed successfully
✖ Error: pngquant failed to build, make sure that libpng-dev is installed
at Promise.all.then.arr (/builds/epigone/exportCCN/node_modules/pngquant-bin/node_modules/bin-build/node_modules/execa/index.js:231:11)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)".
info If you think this is a bug, please open a bug report with the information provided in "/builds/epigone/exportCCN/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
:yarn_install FAILED
You need to modify the permissions on your git repo.
Run:
git update-index --chmod=+x gradlew
then commit and push.

Travis.ci config and execution of npm scripts

I'm trying to use Travis for an open source build of a PR. The configuration is quite simple and the logs seem to show that the appropriate modules are installed upon running yarn install and I am installing the same version of yarn as that which is used locally. The issue is that when I try to execute the scripts defined in the package.json scripts object the modules are not found when running in Travis. Below is the config and the errors I receive at build time.
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.7.0
- export PATH="$HOME/.yarn/bin:$PATH"
cache:
yarn: true
directories:
- "node_modules"
env:
- NODE_ENV=production
language: node_js
node_js:
- 8
- 9
- "stable"
install:
- yarn install
script:
- yarn run lint
- yarn test
The above producing the following output in the build logs:
yarn run v1.7.0
$ ./node_modules/.bin/eslint src/**
/bin/sh: 1: ./node_modules/.bin/eslint: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command "yarn run lint" exited with 1.
0.54s$ yarn run test
yarn run v1.7.0
$ ./node_modules/.bin/jest
/bin/sh: 1: ./node_modules/.bin/jest: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command "yarn run test" exited with 1.
The package.json for this project is as follows:
"scripts": {
"test": "./node_modules/.bin/jest",
"lint": "./node_modules/.bin/eslint src/**",
"precommit": "lint-staged",
"format": "prettier --trailing-comma es5 --single-quote --write 'src/*/*.js' '!(node_modules)/**/*.js'"
},
Was having the same issue and was able to solve it by doing the following in package.json file
"scripts": {
"test": "test --passWithNoTests",
}

Resources