Jenkins Slave (service) , cannot detect protractor - jenkins

We are using slave as service and we r trying to run protractor with simple batch file after calling to npm install , but from some reason protractor was not detected, do u know what could be the reason/problem?
if i use web option (slave) for running job - everything went fine,
BTW - I try to set the service with user that allowed to run the test, and also set node in PATH, but nothing help
Appreciate your comments,
Thanks
Eyal

because you install protractor as a global package, So you should use webdriver-manager from global package install folder. The current folder where you execute npm install -g protractor has no webdriver-manager this cmd/binary. So jenkins report can't find webdriver-manager in current folder or PATH.
For best practice, you should add protractor as your nodejs project's dependency through npm install -S protractor before you write script, after do that, you will found 'protractor' will be add into package.json.
When others who get your source code, he only need to execute npm install under folder where package.json insides to get all dependencies installed.
After npm install done, the webdriver-manager will be found <package.json file inside folder>\node_modules\.bin\webriver-manager
So your cmd should write down as following:
pwd
ls -l "${WORKSPACE}"
cd /d <package.json file inside folder>
npm install
node_modules\.bin\webdriver-manager update
node_modules\.bin\protractor conf.js

Related

Jenkins on ec2 not recognizing composer or npm - both are installed

I've installed Jenkins on an Amazon ec2 instance according to the instructions here https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos and when I try to run a job that has an execute shell command step that does "composer install" or "npm install" it isn't recognizing either command. However from the terminal (as ec2-user) I can run both. Is there something I need to do to let Jenkins know where to find these commands?
I just realized I can sudo su jenkins and install composer as that user.
For NPM, this article helped. You need to install the nodejs plugin, restart Jenkins, then in the build environment section of the configuration of your job, choose "Provide Node & npm bin/ folder to PATH".
I was still having problems running ng commands - after installing the ng client as the jenkins user. This post helped - which says to add "npm run" before ng.
I hope this helps someone. Especially since I figured it out moments after offering my bounty!

Build/deploy Vue.js project through Jenkins

I am new to Jenkins but have done a few builds/deployment jobs of .net project successfully.
Now I am trying to build/deploy Vue.js project through Jenkins but just cannot get through...
I can build the project directly on a server using command prompt. It builds and creates files for deployment in a right directory.
When I am trying to do it in Jenkins job (using the same npm commands) it does not give any error messages, says it built successfully but it does NOT create any files for deployment.
Does anybody encounter this problem? Did anybody build Vue js project through Jenkins? Any help appreciated. Thanks!
In execute windows batch command I run:
cd myworkdirectory
npm install
npm run build
Not too complex, as I found.
Create freestyle project.
In section Source Code Management please define your repository.
In section Build Triggers please define triggers
In section Build define either Execute Windows batch command or Execute shell within sections like (my choice in the moment - windows):
git checkout develop
npm -g install
npm run build
del /s /f /q c:\applications\frontend-app-build\*.*
for /f %%f in ('dir /ad /b c:\applications\frontend-app-build\') do rd /s /q c:\applications\frontend-app-build\%%f
robocopy dist c:\applications\frontend-app-build\ /E

Using cypress behind proxy in Jenkins pipeline

I have seen this on github but I was still not able to get cypress to configure/download correctly. In my jenkins pipeline I run npm install but this runs into a timeout because of the proxy. It downloads all other dependencies expect cypress.
What I did was download cypress and put the zip file in the project. I then run sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress" but this still fails.
Part that fails in Jenkins pipeline:
sh "npm config set proxy http://<proxy>"
sh "npm config set registry http://<proxy>/"
sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress"
sh "npm i"
sh "npm run build
How can I have npm i run without download cypress. I currently cannot get passed this line sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress" but I am also concerned npm i will still try to download cypress after setCYPRESS_INSTALL_BINARY actually works
-------------------------Update One-----------------
I updated the Jenkinsfile to have CYPRESS_INSTALL_BINARY=cypress.zip npm i but now I get the below error. Cypress.zip is in the project now but would really like to have it uploaded to Jenkins and just reference the file path within my Jenkinsfile.
I am not sure that is possible and the most simple solution is the one I am doing I think however it fails.
New error:
[view] Running shell script
+ CYPRESS_INSTALL_BINARY=cypress.zip
+ npm install
npm WARN locking Error: EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
npm WARN locking /home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock failed { Error: EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
npm WARN locking stack: 'Error: EIO: i/o error, open \'/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock\'',
npm WARN locking errno: -5,
npm WARN locking code: 'EIO',
npm WARN locking syscall: 'open',
npm WARN locking path: '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock' }
npm ERR! path /home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock
npm ERR! code EIO
npm ERR! errno -5
npm ERR! syscall open
npm ERR! EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
script returned exit code 251
I had similar issues on Windows environment. I placed cypress.zip into project's root folder.
set CYPRESS_INSTALL_BINARY=cypress.zip
echo %CYPRESS_INSTALL_BINARY%
npm install cypress --save-dev
So installation did not work, because npm executable looks for cypress in <your project folder>\node_modules\cypress\
Try to set CYPRESS_INSTALL_BINARY to absolute path.
I'm assuming you're on linux, so the way to set an environment variable is CYPRESS_INSTALL_BINARY='cypress.zip' ("set " is only used on Windows)
Cypress will not try to download the binary if it's found on the system, even when running npm install again. By default Cypress downloads the binary to ~/.cache/Cypress, so on subsequent builds Cypress will not have to extract the zip if this directory persists between builds.
The following should work:
CYPRESS_INSTALL_BINARY='cypress.zip` npm install
no need to explicitly run npm install cypress
Then, ensure the ~/.cache directory is saved after and restored before npm install across builds.
or
Pre-extract the cypress.zip onto the build system to /Cypress, and use the following:
CYPRESS_INSTALL_BINARY=0 npm install ## Don't install the binary!
CYPRESS_RUN_BINARY='Cypress/Cypress' ## this is the Cypress executable!
again, make sure /Cypress persists across builds
What if I don't cache ~/.cache ?
Well, your build will still run, but take significantly longer as Cypress will have to extract its binary on every build. Read more here about caching the binary in CI
...
Edit: For Question Update
You're still not setting environment variables correctly. This will not work:
CYPRESS_INSTALL_BINARY='cypress.zip'
npm install
You need to do:
CYPRESS_INSTALL_BINARY='cypress.zip' npm install
In one line.
or
export CYPRESS_INSTALL_BINARY='cypress.zip'
npm install
-> Why here
I created a tool to deal with this problem:
https://github.com/tomasbjerre/dictator-cypress-example
You would need to clone this repository and publish your own cypress-dictator to your private npm repository:
https://github.com/tomasbjerre/dictator-cypress
It uses dictator builder to, before npm install, copy platform specific zip-files to root of repository and make sure it is pointed at by .npmrc.
{
"message": "Copy linux cypress to cypress.zip",
"triggers": [
{
"runningOnPlatform": ["linux"]
}
],
"actions": [
{
"copyFrom": "linux-x64.zip",
"target": "cypress.zip"
}
]
}

Thingsboard UI Customization

I would love to be able to customize the UI to fit the guidelines of our brand.
I'm not very familiar with Sass and Angular.
Can you suggest which IDE, tools or plugins are best in this particular project to modify and test the UI without having to build the whole project every time?
Thank you!
thingsboard ui is using angularjs, react, webpack, babel and ...
but all of the ui is connected to all project and i couldn't run it separate and after npm install and npm run build had some problems . based on pom.xml file in ui folder the project first is build with maven and make a jar file in ui folder then run it as front-end module . if we want not to clean install maven every time we change the project, one way is to run commands in pom.xml file ourselves . because the project does not use our global installed npm and node first it installs the particular version of them (nodeVersion: v6.9.1 npmVersion: 3.10.8) locally in ui folder then move them to folder named node and make link to node_modules : ln -s node_modules/npm/bin/npm-cli.js npm after this run the commands:
node/npm install
node/npm run build
node/npm start
so you can write a script file to run all this commands together . don't forget to change your tb-gateway forwardHost and forwardPort in server.js file . the script file based on my os :
#!/usr/bin/env bash
if [ ! -d node-v6.9.1-linux-x64 ] ; then
wget https://nodejs.org/dist/v6.9.1/node-v6.9.1-linux-x64.tar.gz
tar -xzvf node-v6.9.1-linux-x64.tar.gz
mkdir node
mv node-v6.9.1-linux-x64/lib/node_modules node/
mv node-v6.9.1-linux-x64/bin/* node/
cd node
ln -s node_modules/npm/bin/npm-cli.js npm
cd ..
fi
node/npm install
node/npm run build
node/npm start
after all this every ui project build will take time . you can use webstorm IDE or some web ides to open ui folder .

Grunt integration with Jenkins on windows issue

I am running Jenkins on Tomcat7 - Windows 7. I have provided the node bin path in my jenkins configuration. Then running a shell script as follows:
echo $PATH
node --version
npm install -g grunt-cli
npm install
grunt cssmin
As suggested in other post Jenkins integration with Grunt, I have restarted my jenkins several times, and tried to work on all the answers written in that post, but still it shows error, grunt: command not found.
Error stack trace from jenkins console output:
/c/apache-maven-3.2.5/bin:/c/Program Files/Java/jdk1.7.0_79/bin:/c/Program Files/nodejs/bin:/c/Program Files/Java/jdk1.7.0_79/bin:/c/Program Files/nodejs/:
+ node --version
v0.10.30
+ npm install -g grunt-cli
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\grunt -> C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
grunt-cli#0.1.13 C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\node_modules\grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.7)
└── findup-sync#0.1.3 (lodash#2.4.2, glob#3.2.11)
+ npm install
npm WARN package.json Trademust#1.0.0 No repository field.
+ grunt cssmin
C:\Program Files\Apache Software Foundation\Tomcat 7.0\temp\hudson2968878175697925824.sh: line 6: grunt: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I have also followed the steps mentioned on this site grunt-on-jenkins
package.json and Gruntfile.js are in root directory the very first time when I executed the jenkins build, grunt installed all modules from my gruntfile.js, and after that in all other build's its showing the above output.
Can anyone please check what's going on wrong here.
After searching a lot, I found where my grunt is installed. As far as jenkins build is concerned it installs in drive:/.jenkins....../workspace/node_modules/.bin.
After providing this path in jenkins using shell script export path=$PATH:drive:/.jenkins....../workspace/node_modules/.bin, grunt started executing.
Also what I learnt in this process was checking where the executable's are available on system path or which path jenkins refers to is using which "executable_name" without qoutes. you can use this command both on windows as well as linux. Ex: which grunt will show the path where grunt executable file is present.
From the error message it seems, sheel is not able to find grunt. Could you please check if it is present in the $PATH variable. On which node this shell script is running? You cab check the $PATH of the particular node. You can also add grunt installation path to $PATH variable during the shell script.
grunt_path="grunt_installtion_path"
export PATH=${PATH}:${grunt_path}

Resources