Showing posts with label Jenkins. Show all posts
Showing posts with label Jenkins. Show all posts

Monday, 4 February 2019

Convienece start up guide

In /home/user_name/
:
create .tmux.conf (use contorl a  + hjk to fly around)
create .inputrc (gives useful history command, !number gives that command, or command uparrow gives recent used command)
create .bashrc
.vimrc (use only one line set directory = ~/.vimbak)
create dir vimbak,
chmod 700 vimbak(this is to set .swp file created by vim in this folder)

copy configurations from my colleagues git repo:

https://github.com/junxie6/config_centos_v2


useful linux command can be found:
https://github.com/junxie6/config_centos_v2/blob/master/.vimrc

Linux user group, permission

# linxu && command:
a && b
$ false || echo "Oops, fail"
Oops, fail

$ true || echo "Will not be printed"
$  

$ true && echo "Things went well"
Things went well

$ false && echo "Will not be printed"
$

$ false ; echo "This will always run"
This will always run

#linx next line within same command \

# linux git clone if not existed, else update
if cd repo; then git pull; else git clone https://server/repo repo; fi

# source .bashrc will give latest bash command such as ll, and so on.
# without .profile, need to source .bashrc every time after login, set up .profile

#linux user without user@user displayed
chsh
then change to /bin/bash


# linux user created without home folder:

mkhomedir_helper username
# Examine current machine IP && IPs that other process has taken
ip addr

# Get current workign dir:
pwd

# SSH notes: recall ssh is generated by (it must be created by the user you wanted to ssh in to the other remote. i.e my_user_name)
$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
#copy to remote server can be done: (ssh-copy-id user@hostname.example.com)
ssh-copy-id id@server
This copies the public key in the current server to the remote server

SSH to git:
$ in git add a deploy key(set whether can ssh using pull or push or both)
copy the public key (everything) in /home/username/.ssh/id_rsa.pub 
in deploy key content
$ now can try git clone ssh://git....



# best pratice is to avoid using root user as possible, we can give sudo permission group to a user to let the user to execute stuff as root using sudo

# execute sudo without entering password
sudo visudo
opened by nano, added NOPASSWD:ALL(only good for dev server for making things fast)

# Allow members of group sudo to execute any command       for nano ^ means ctrl , so ctrl + X is to quit                                                
%sudo   ALL=(ALL:ALL) NOPASSWD:ALL                                                                        


# create a user  with home folder(-m) and shared bin/bash (-s/bin/bash)
useradd -m -s/bin/bash user_name_you_want

# change to a user
sudo su user_name

# set user password
passwd user

# append a group to user
usermod -aG group_you_want user_name_you_want

# check for a user current groups(sudo, docker, docker has its own group, once assigned, no need to sudo docker anymore)
id user_name_you_want

# list all user groups
cut -d: -f1 /etc/group | sort
# list all local users #jenkins will create a user called jenkins. when generating ssh private/public keys for jenkins, need to use jenkins user
cut -d: -f1 /etc/passwd

Friday, 1 February 2019

Jenkins post build email

https://www.youtube.com/watch?v=DULs4Wq4xMg#action=share
https://stackoverflow.com/questions/18106160/jenkins-email-ext-plugin-not-sending-mail

Jenkins workspace location && useful plugins

  1. Navigate to Jenkins -> Manage Jenkins -> Configure System
  2. Right at the top, under Home directory
By default, Jenkins stores all of its data in this directory on the file system.
There are a few ways to change the Jenkins home directory:
  • Edit the JENKINS_HOME variable in your Jenkins configuration file (e.g. /etc/sysconfig/jenkins on Red Hat Linux).
  • Use your web container's admin tool to set the JENKINS_HOME environment variable.
  • Set the environment variable JENKINS_HOME before launching your web container, or before launching Jenkins directly from the WAR file.
  • Set the JENKINS_HOME Java system property when launching your web container, or when launching Jenkins directly from the WAR file.
  • Modify web.xml in jenkins.war (or its expanded image in your web container). This is not recommended.
This value cannot be changed while Jenkins is running. 
It is shown here to help you ensure that your configuration is taking effect.



Default location in Home Directory is
/var/lib/jenkins
# cd to workspace directory to see a list of workspaces you have created
$ cd /var/lib/jenkins/workspace/

Useful plugins Junit for unit test logs && webhook for hooking up git 
(usually installed as default, listed in plugins)
https://plugins.jenkins.io/junit
https://wiki.jenkins.io/display/JENKINS/Generic+Webhook+Trigger+Plugin

view these plugins for sample usage
sample command for running php unit test && log with junit
cd ./mygit-repo/
composer install
./vendor/bin/phpunit ./tests/Feature/test.php --log-junit ./tests/JunitResults/*.xml

Junit repo default directory is workspace root directory
which is  /var/lib/jenkins/workspace/your_current_workspace/

sources:
https://stackoverflow.com/questions/34854377/how-to-change-workspace-and-build-record-root-directory-on-jenkins


Tuesday, 29 January 2019

How To Install Jenkins on Ubuntu 18.04


To install Jenkins on your Ubuntu system, follow these steps:
  1. Install Java.
    Since Jenkins is a Java application, the first step is to install Java. Update the package index and install the Java 8 OpenJDK package with the following commands:
    sudo apt updatesudo apt install openjdk-8-jdk
    Copy
    The current version of Jenkins does not support Java 10 (and Java 11) yet. If you have multiple versions of Java installed on your machine make sure Java 8 is the default Java version.
  2. Add the Jenkins Debian repository.
    Import the GPG keys of the Jenkins repository using the following wgetcommand:
    wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
    Copy
    The commands above should output OK which means that the key has been successfully imported and packages from this repository will be considered trusted.
    Next, add the Jenkins repository to the system with:
    sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    Copy
  3. Install Jenkins.
    Once the Jenkins repository is enabled, update the apt package list and install the latest version of Jenkins by typing:
    sudo apt updatesudo apt install jenkins
    Copy
    Jenkins service will automatically start after the installation process is complete. You can verify it by printing the service status:
    systemctl status jenkins
    Copy
    You should see something similar to this:
    ● jenkins.service - LSB: Start Jenkins at boot time
    Loaded: loaded (/etc/init.d/jenkins; generated)
    Active: active (exited) since Wed 2018-08-22 13:03:08 PDT; 2min 16s ago
        Docs: man:systemd-sysv-generator(8)
        Tasks: 0 (limit: 2319)
    CGroup: /system.slice/jenkins.service
    Copy
https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/