Giter Club home page Giter Club logo

jenkins-cicd-intro's Introduction

Jenkins CICD Introduction Demo Code and Configs

Contains Jenkins code and configuration examples as used within the Introduction to CI/CD with Jenkins course.

Demo 4: Install Jenkins - EC2 Ubuntu

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

Demo 5: Install Jenkins - Docker Compose

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 

Demo 6: Create Basic Freestyle Project

UI instructions only

Demo 7: Create Basic Freestyle Project

UI instructions only

Demo 8: Building a GitHub Stored Project

Refs https://github.com/cloudacademy/react-webapp

Notes:

  • this demo assumes yarn (1.22.x) and node (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 the yarn build to complete successfully

Install and Setup yarn and node locally (MacOS)

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

Jenkins Script

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!!

Demo 9: Build Triggers with GitHub Hooks

Documentation https://api.github.com/meta

Refs https://github.com/cloudacademy/react-webapp

Demo 13: Build Pipelines - Maven

Uses provided sample pipeline within the Jenkins UI

Demo 14: Build Pipelines - Scripted

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!!" 
        }

    }
}

Demo 15: Build Pipelines - Gradle

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

====================

Demo 16: Build Pipelines - Declarative

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"
            }
        }
    }
}

jenkins-cicd-intro's People

Contributors

jeremycook123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.