Sunday, 7 January 2018

Setup Jenkins: A continuous integration and continuous deployment toll on Ubuntu 14.04 machine for an Angular4 appication

How to setup jenkins in ubutu 14.04


SRC: https://vexxhost.com/resources/tutorials/how-to-install-configure-and-use-jenkins-on-ubuntu-14-04/

1) sudo apt-get update

2) Basic Web Server [Only if you want build to be server by a web-server]
apt-get install nginx
Check service status: service nginx status

3) Java Installation
sudo apt-get install openjdk-7-jdk
verify the installation: java –version

4) Jenkins Installation and Configuration
a) wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add –
b) sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
c) sudo apt-get install Jenkins

Default user name [jenkin]
Jenkins Continuous Integration Server is running with the pid 16997
Port: 8080

If you need to update the configurations of Jenkins as per your requirements, then you can find its configuration file under the `/etc/default/` directory and can make the changes.
root@ubuntu-14:~# vim /etc/default/Jenkins

5) Setup Jenkins
To use and configure Jenkins, visit the following address in your browser

a) http://your-ip-address:8080
b) 1. Click on `Manage Jenkins` and then choose the required parameter to start required configurations.
2.

jenkins  todos

master branch should be replace by develop  branch
git should be replaced by butbucket.


sudo usermod -a -G root jenkins
Then restart jenkins:

sudo service jenkins restart


https://codeforgeek.com/2016/04/continuous-integration-deployment-jenkins-node-js/

https://medium.com/nodejs-tips/jenkins-node-js-part-2-b499c280310a

forever: https://www.npmjs.com/package/forever


***************************

echo $PATH
node --version
forever --version
echo "Install modules"
npm install
echo "Stoping forever old process"
forever stop index.js
echo "Starting forever new process"
BUILD_ID=dontKillMe forever -a -1 myforever.log index.js &


https://stackoverflow.com/questions/30862532/forever-errors-with-babel-node
forever start -c node_modules/.bin/babel-node server.js
*****************************************************************

Here we tell Jenkins not the stop the newly forked child process as it’s execution is over. Using `BUILD_ID=dontKillMe` flag. As this process needs to be up and running even are the build is over. Do note & at the end, it used to make the command a background process, thus jenkins process will not wait for it and skip to next command, thus allow the build to be complete.

***************************

sudo nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &

sudo nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &


forever start -c node_modules/.bin/babel-node server.js

Problems left behind:

how to take git pull since that requirese username and password

how to trigger git code from bitbucket to jenkins

how to link with another branch then master

to test with a live running Angular application.

kill command fails when no application has been running

Problems solved
How to kill a process started with nohup on port # 4001
sudo kill `sudo lsof -t -i:4001`

how to provide password to sudo command
https://stackoverflow.com/questions/37603621/jenkins-sudo-no-tty-present-and-no-askpass-program-specified-with-nopasswd

# User privilege specification
root    ALL=(ALL:ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL

cannot create ./log.txt: Permission denied
give it the permission manually, since jenkins creates its own user which might has permissions different from the ordinary user.




Process I will follow

echo $PATH
node --version
echo "Stoping forever old process"
sudo kill `sudo lsof -t -i:4200`
echo "Starting forever new process"
nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &

sudo kill `sudo lsof -t -i:4200`
sudo nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &

echo "Sudo_password" | sudo -S pwd

How to run mongod
sudo mongod --dbpath=/var/lib/mongodb


SRCS:
How to setup
https://vexxhost.com/resources/tutorials/how-to-install-configure-and-use-jenkins-on-ubuntu-14-04/
Link bitcuket as well: https://medium.com/nodejs-tips/jenkins-node-js-part-2-b499c280310a
how to use sudo in jenkins
WOrked: https://stackoverflow.com/questions/37603621/jenkins-sudo-no-tty-present-and-no-askpass-program-specified-with-nopasswd
Not worked for me: https://stackoverflow.com/questions/21659637/how-to-fix-sudo-no-tty-present-and-no-askpass-program-specified-error/24648413#24648413
Link bitbucket to jenkins
https://medium.com/nodejs-tips/jenkins-node-js-part-2-b499c280310a

No comments:

Post a Comment