Contains Jenkins code and configuration examples as used within the Introduction to CI/CD with Jenkins course.
Install intructions for Ubuntu 18.04
sudo -s
apt-get update
apt-get install -y openjdk-8-jdk
java -version
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update
apt-get install -y jenkins
systemctl status jenkins
ps -ef | grep jenkins
ufw status
ufw allow 8080
cat /var/lib/jenkins/secrets/initialAdminPassword
mkdir jenkins-docker
cd jenkins-docker
docker network create -d bridge devnetwork
docker-compose.yml
version: "3.5"
services:
jenkins:
container_name: jenkins-docker
image: jenkins/jenkins:lts
ports:
- 8080:8080
networks:
- devnetwork
networks:
devnetwork:
name: devnetwork
docker-compose config
docker-compose up -d && docker-compose logs -f
docker ps
docker exec -it jenkins-docker bash
docker exec -it jenkins-docker /var/lib/jenkins_home/secrets/initialAdminPassword
UI instructions only
UI instructions only
Refs https://github.com/cloudacademy/react-webapp
Notes:
- this demo assumes
yarn
(1.22.x) andnode
(8.x) have already been installed and is available on the host that the Jenkins service is running on. node
version 8.x is required for theyarn build
to complete successfully
If you are running Jenkins locally on MacOS then perform the following instructions to install yarn
and node
brew install yarn
yarn --version
which yarn
brew install n
sudo n 8.10.0
node --version
which node
Update the PATH and preappend /usr/local/bin
to it - so that yarn
can be found by the Jenkins service when the build is executed
PATH=/usr/local/bin:$PATH
echo $PATH
yarn --version
node --version
yarn install
yarn build
ls -la
echo finished!!
Documentation https://api.github.com/meta
Refs https://github.com/cloudacademy/react-webapp
Uses provided sample pipeline within the Jenkins UI
def int fibonacci(int n){
n < 2 ? n : fibonacci(n-1) + fibonacci(n-2)
}
node{
def workspace = pwd()
echo "workspace = ${workspace}"
def nine = 9
def ten = nine + 1
stage('Calculate'){
try{
if(ten > nine){
echo "${fibonacci(ten)}"
sh returnStdout: true, script: 'script-which-doesnt-exist.sh'
}
}
catch(exc){
echo "some exception just happened!!"
}
}
}
Refs https://github.com/cloudacademy/devops-webapp
Website https://crontab.guru/
H/5 * * * *
//START-OF-SCRIPT
node {
def GRADLE_HOME = tool name: 'gradle-4.10.2', type: 'hudson.plugins.gradle.GradleInstallation'
sh "${GRADLE_HOME}/bin/gradle tasks"
stage('Clone') {
git url: 'https://github.com/cloudacademy/devops-webapp.git'
}
stage('Build') {
sh "${GRADLE_HOME}/bin/gradle build"
}
stage('Archive') {
archiveArtifacts 'build/libs/*.war'
}
}
//END-OF-SCRIPT
sudo apt-get install -y tree
cd /var/lib/jenkins/workspace/BuildJob6
ls -la
cd build
tree
====================
Refs https://github.com/cloudacademy/devops-webapp
pipeline {
agent {
label 'master'
}
tools {
gradle 'gradle-4.10.2'
}
environment {
VERSION = "jellybean"
}
stages{
stage('Checkout') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: 'master']],
extenstions: [[$class: 'WipeWorkspace']],
userRemoteConfigs: [[url: 'https://github.com/cloudacademy/devops-webapp.git']]
])
}
}
stage('Details') {
steps {
echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
echo "${env.VERSION}"
}
when {
environment name: 'VERSION', value: 'jellybean'
}
}
stage('Build') {
steps {
sh "gradle build"
}
}
}
}