Jenkins
Jenkins
•
• 1 pwd
• 2 sudo yum update
• 3 sudo yum update -y
• 4 sudo su -
• 5 java -version
• 6 sudo yum install java-1.8.0
• 7 clear
• 8 java -version
• 9 sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-
• stable/jenkins.repo
• 10 sudo yum update
• 11 sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
• 12 sudo yum upgrade
• 13 sudo yum install jenkins java-11-openjdk-devel
• 14 sudo systemctl daemon-reload
• 15 sudo service jenkins start
• 16 sudo cat /var/lib/jenkins/secrets/initialAdminPassword
• To change Jenkins port in redhat linux
• Go to /etc/sysconfig – goto Jenkins file – change port from 8080 to new port
• Bomboo
• Jenkins – very popular- 100s plugins+good community support+open source
• Teamcity
MAVEN LIFECYCLE
• Clean
• Site
• Default
• Default life cycle has following:
• Validate: Validate the project is correct and all necessary information is available
• Compile: Compile the source code of he project
• Test: Runs suitable test cases. These tests should not be required code be packaged or deployed
• Package: Take the compiled code and packageit in istributable form like Jar, War, Ear
• Install: Install the package into the local repository, for use as a dependency in other projects locally
• Deploy: Copies the final package to the remote repositorys for sharing with other developers and projects
• Clean lifecycle: Removes all files generated by other project
• Maven Goals:
• To invoke a maven build you set a life cycle goal
• Mvn install: it invokes validate, compile, test, package, install
• Mvn clean: it invokes just clean
• Mvn clean compile: clean old builds and execute validate and compile
• Mvn compile install: invokes validate compile test package install
• Mvn test clean: invokes validate compile test clean
• How to create Users + Manage + Assign Roles
• Step 1 : Create new users
• Step 2 : Configure users
• Step 3 : Create and manage user roles Role Based Authorization Strategy Plugin -
Matrix Authorization Strategy Plugin- download - restart jenkins
• Step 4 : Manage Jenkins - Configure Global Security - Authorization - Role Based
Strategy –Apply-Save
• Step 5 : To Create Roles and Assign roles to users-Manage Jenkins-Manage and Assign
roles-
• Step 6 : Validate authorization and authentication are working properly
• Create the first github Job on Jenkins
• How to connect to Git Remote Repository in Jenkins (GitHub)
• Install Credentials plugin
• Goto Credentials in Jenkins
• Click on Jenkins
• Click on add credentials
• Select KIND as username and password
• Add github credentials
• Get the url of the remote repository
• Add the git credentials on Jenkins
• In the jobs configuration goto SCM and provide git repo url in git section
• Add the credentials
• Run job and check if the repository is cloned
• Chain Jobs
• Upstream
• Downstream
• Checkout from github
• Build periodically
• Shell command
• Install maven
• Maven invoker plugin
• Chain jobs
• Build pipeline plugin- for chian jobs
• Pipeline
MAVEN
• install maven - https://maven.apache.org/download.cgi
• Cd /opt/maven
• wget
https://mirrors.estointernet.in/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
• tar -xvzf apache-maven-3.8.1-bin.tar.gz
• cd apache-maven-3.8.1/
• pwd
• cd /
• vi .bash_profile
• echo $PATH
• mvn –version
• Vi .bash_profile
• # User specific environment and startup programs
• PATH=$PATH:$HOME/bin
• JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64/jre"
• M2_HOME=/opt/maven/apache-maven-3.8.1
• M2=$M2_HOME/bin
• PATH=$PATH:$JAVA_HOME:$M2_HOME:$M2:$HOME/bin
• export PATH
• Stage1-Git checkout- mention github
• Stage2- Build project- mvn/ant-
• Stage3- Test-Junit/seli
• Stage4-Deploy config
• Stage5- Post-push artifacts
• Install maven invoker plugin
• Install github plugin
• Install pipeline plugin
• pipeline {
• agent any
• stages {
• stage("HELLO"){
• steps{
• echo "Hello Welcome to Devops"
• }
• }
• }
• }
• pipeline {
• agent any
• stages {
• stage('NORMAL Stage') {
• steps {
• echo 'I am one' }
• }
• stage('Parallel Stage') {
• steps { echo "Me in stage one"
• }
• }
• stage('Stage two') {
• steps {
• echo "Me in stage two"
• }
• }
• stage('Stage three') {
• steps {
• echo "Me in stage three" } } } }
• Parameterized builds
• Tihs project is parameterized – add parameter – string parameter --
• Enter name(parameter name) and default value