Getting Started with Jenkins: A VMWorld workshop.

36
Getting Started with Jenkins: A VMWorld workshop

Transcript of Getting Started with Jenkins: A VMWorld workshop.

Page 1: Getting Started with Jenkins: A VMWorld workshop.

Getting Started with Jenkins:

A VMWorld workshop

Page 2: Getting Started with Jenkins: A VMWorld workshop.

2

Introductions

Bob Webster

Technical Marketing Manager

VMware vCloud Air

[email protected]

@rdpwebster

Eric Smalling

Consulting Architect

DevOps by VMware Professional Services

[email protected]

@ericsmalling

Page 3: Getting Started with Jenkins: A VMWorld workshop.

About Us: VMware DevOps Consulting Services

Build and deliver applications sooner

Fuel innovation and accelerate time to market

Transform your enterprise to support high velocity, modern application development

Deploy an agile future-ready datacenter where any app can thrive

3

Developer friendly. Enterprise ready.

• Assessment • Strategy development• People, process & technology

transformation for• Continuous delivery• Configuration management • Cloud operations

• Security & resilience optimization

Our team of dedicated DevOps experts provide:

Page 4: Getting Started with Jenkins: A VMWorld workshop.

4

Agenda

• What is Jenkins?

• Installing Jenkins

• Lab1: A Quick Tour of Jenkins

• Configuring Jenkins & Plugins

• Lab2: CI with Jenkins

• Demo: vSphere Integration

Page 5: Getting Started with Jenkins: A VMWorld workshop.

What is Jenkins?

Page 6: Getting Started with Jenkins: A VMWorld workshop.

6

Jenkins

• Jenkins is a free / Open Source application that monitors the executions of repeated jobs

• It’s primarily used as a Continuous Integration Tool for building software.

• Jenkins Home Page http://jenkins-ci.org/

Page 7: Getting Started with Jenkins: A VMWorld workshop.

7

Jenkins and HudsonToo many butlers?

• Before Jenkins, there was Hudson.

• Hudson was written by Kohsuke Kawaguchi at Sun Microsystems

• When Oracle bought Sun and planned for a Commercial version of Hudson, the open source community including Kohsuke Kawaguchi created Jenkins.

• Interest in Hudson declined dramatically and Oracle donated the source to the Eclipse Foundation in 2012

• Today, Jenkins is a much more active project.

Page 8: Getting Started with Jenkins: A VMWorld workshop.

Installing Jenkins

Page 9: Getting Started with Jenkins: A VMWorld workshop.

9

Installing Jenkins

• The Jenkins Home Page

http://jenkins-ci.org

provides native package installers for many platforms.

• In this workshop we will coverinstallation for Windows and OSX.

• Long Term Stable (LTS) version is usually the best for most uses.

Page 10: Getting Started with Jenkins: A VMWorld workshop.

10

Windows Installas a windows service

1. Visit the Jenkins home page http://jenkins-ci.org

2. Click on the Windows native package installer link and download the package

3. Unzip the package

4. Run the installer

5. When complete, access the Jenkins home page on your laptopat http://localhost:8080/

1. Ensure Java is installed (run “java” at Terminal and follow prompts if it’s not installed yet)

2. Visit the Jenkins home page http://jenkins-ci.org

3. Click on the Mac OSX native package installer link and download the package

4. Double click the .pkg in the downloads folder on your Mac.

5. Enter your admin password to permit the install.

6. When the installer loads, accept the license and accept all defaults.

7. When complete, access the Jenkins home page on your laptop at http://localhost:8080/

Mac OSX Install

Start / Stop Daemon:

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

Start / Stop Service:

To start/stop them manually, use the service manager from the control panel

Page 11: Getting Started with Jenkins: A VMWorld workshop.

11

Run via Java Command Line1. Visit the Jenkins home page http://jenkins-

ci.org

2. Click on the link under “Java Web Archive (.war)

3. Open a shell and cd to the download directory

4. Run this command: “java –jar jenkins.war”

5. Access the Jenkins home page on your laptopat http://localhost:8080/

6. CTRL-C will kill the process

1. docker pull jenkins

2. docker run jenkins_home

(You’ll probably want to attach a volume for Jenkins to store its data)

Run in Docker container

Page 12: Getting Started with Jenkins: A VMWorld workshop.

12

Install Git

Windows

1. Visit the linkhttp://git-scm.com/downloads

2. Click on the Windows download icon

3. Click on the downloaded .exe file to run the installer.

1. Select ‘Use Git from the Windows Command Prompt’

2. Accept all other defaults

• Mac OSX

• Open Terminal, type “git”. If not installed a window should prompt you to install the XCode command line tools. Click “Install”.

• Other options:– http://git-scm.com/downloads

– Homebrew users: brew install git

Page 13: Getting Started with Jenkins: A VMWorld workshop.

Lab 1: A Quick Tour of Jenkins• Create a simple job

• View execution results

• Show how errors are reported

Page 14: Getting Started with Jenkins: A VMWorld workshop.

14

Lab 1: Quick Tour of Jenkins

• Step 1:– Click “create new jobs” or “New Item”

• Step 2:– Give your job a name

– Select “Freestyle Project”

– Click “OK”

• Step 3:– Scroll down to the “Build” section

– Click “Add build step” and select either “Execute shell” (Mac) or “Execute batch command” (Windows) from the drop down menu.

Page 15: Getting Started with Jenkins: A VMWorld workshop.

15

Lab 1: Quick Tour of Jenkins

• Step 4:– Add a script that logs lines over several seconds

– Click “Save”

• Step 5:– You are presented with the project status page

– Click “Build Now” to run your project

– Note the build history will change

Page 16: Getting Started with Jenkins: A VMWorld workshop.

16

Lab 1: Quick Tour of Jenkins• Step 6:

– Click the “1” link to open that run’s status page

– This job is very basic so not much info is presented; a lot more data can be shown on this page (more on that later).

– Note the “Sunny” icon in the Build History panel. This indicates relative build status over the last several builds. Sunny = all passing

• Step 7:– Click “Console Output” on the left side of the page

– The console output of the running job is listed

– NOTE: If you open this page while the job is still running, the log will be live, scrolling as more data comes in. (similar to “tail –f”)

– Tip: Clicking the ball or progress bar in the “Build History” panel will take you straight to the that run’s console output.

Page 17: Getting Started with Jenkins: A VMWorld workshop.

17

Lab 1: Quick Tour of Jenkins

• Step 8:– Navigate back to your project status page by

clicking on the “Status” link

– Click on the “Configure” link to re-open the project’s configuration form

• Step 9:- Scroll down to the Build -> Execute Shell (or batch

command) section and add “exit 1” to the bottom of the script (same for Windows or Mac)

- Click Save

- Click Build Now

Page 18: Getting Started with Jenkins: A VMWorld workshop.

18

Lab 1: Quick Tour of Jenkins

• Step 10:– Notice the red icon next to the 2nd run in build history

(when it completes the run) which indicates failure.

– Also note the “weather” icon has changed to “cloudy” because we have 50% failure rate.

• Step 11:- Go back into the configuration page (click “Configure”)

- Remove the “exit 1” line you added earlier

- Click Save

- Click Build Now

- The 3rd run should go back to Blue/Pass state

- Weather is now “partly sunny” as the builds are now 66% passing.

Page 19: Getting Started with Jenkins: A VMWorld workshop.

Configuring Jenkins & Plugins

Page 20: Getting Started with Jenkins: A VMWorld workshop.

20

Configuring Jenkins

• Configure System– Central place for global configuration settings

– Plugins can add sections if needed

– Allows system-wide governance of the build tools used• JDK versions• Ruby versions

• Configure Global Security– Several authentication options

– Provides various levels of authorization granularity

– Extensible by plugins

• Secure credential store– Manages credentials for external systems so that

projects don’t have to invent their own schemes.

Page 21: Getting Started with Jenkins: A VMWorld workshop.

21

Jenkins Plugins

• Jenkins has over a thousand plugins that extend its functionality.

• Extensibility points within Jenkins enable anyone to create a plugin.

• A list of all available plugins is available on the Jenkins Plugin Page

https://wiki.jenkins-ci.org/display/JENKINS/Plugins

• In this tutorial we will be using these plugins– GitHub plugin

Page 22: Getting Started with Jenkins: A VMWorld workshop.

Lab 2: CI with Jenkins• Setup a continuous integration project

• Automatic builds and deploys to vCloud Air

Page 23: Getting Started with Jenkins: A VMWorld workshop.

23

Lab 2: Continuous Integration

• In this lab you will setup a continuous integration project.

• Your project will automatically build and deploys an application to vCloud Air when source changes are made.

• Step 1: Clone (create) a local source code repository on your laptop

• Step 2: Setup a post-commit hook so Git will call Jenkins when code changes are made.

• Step 3: Create a new Jenkins Project that will build the source code

• Step 4: Modify the code and commit the change

• Step 5: Watch Jenkins checkout and deploy the new code

• Step 6: Test the change with a browser

Lab Instructionshttp://devops.vcair.us/labs/jenkins.html

Page 24: Getting Started with Jenkins: A VMWorld workshop.

24

JenkinsMasters and Slaves

• A normal Jenkins install acts as a master and uses its resources to run all jobs.

• An executor is the component the does the work.

• To perform a lot of parallel builds, slaves can be configured to perform work.

• A slave is a computer that is set up to offload build projects from the master and once setup this distribution of tasks is fairly automatic.

• The slave runs a slave agent, a full Jenkins install is not required.

• Jobs can be set to stick to a specific slave for a build or roam across slaves

Page 25: Getting Started with Jenkins: A VMWorld workshop.

Jenkins + vSphere Integration

Page 26: Getting Started with Jenkins: A VMWorld workshop.

26

vSphere Integration

• The vSphere Plugin offers two modes of integration1. In-project build step level

• Perform vSphere operations inline with your job steps• Ensure VM is running before build or test• Shut down VM upon completion• Reset target VMs to known good state before / after job run• etc

2. Automated slave provisioning / de-provisoning• Starts VMs to act as slave instances as load requires them• Shuts VMs down when no longer needed• Useful for build / test spikes• Specialized build platforms/OS’s/tools• Resetting a slave to known good state• etc

Page 27: Getting Started with Jenkins: A VMWorld workshop.

27

vSphere Deployment Demo

Demo prerequisites:

• vSphere ESXI is available and accessible by Jenkins

• A VM is available with Ubuntu 14.04 Server and the following installed:• open-vmtools• Nginx

• /usr/share/nginx/html writable by the user Jenkins will be using.

• A snapshot taking in vSphere of this state

Page 28: Getting Started with Jenkins: A VMWorld workshop.

28

vSphere Deployment Demo

System configuration

1. Install the “vSphere Plugin” and “SSH plugin”

2. On Jenkins Configure System page, go to “Cloud” and select “vSphere Cloud” from the “Add a new cloud” dropdown menu.

3. Enter your vSphere host, credentials and a name for this vSphere Cloud.

4. Click “Test Connection” button to validate connectivity.

5. Scroll up to the “SSH remote hosts” section and click the “Add” button.

6. In the “hostname” field enter “$VSPHERE_IP”.

Page 29: Getting Started with Jenkins: A VMWorld workshop.

29

vSphere Deployment Demo

System configuration (cont.)

7. Fill out the rest of the fields with the credentials for your VM user (ignore server connection form error)

8. Click “Save” at bottom of page.

Create a test job:

9. Create a new “FreeStyle” job.

10. Enable “This build is parameterized” and add a “String Parameter”. Name: TEST_STRING (put anything you want in the “Default Value”

Page 30: Getting Started with Jenkins: A VMWorld workshop.

30

vSphere Deployment Demo

Create a test job (cont.):

3. In the “Build” section add two “vSphere Build Step”s – In the first one, choose your vSphere server (using the

cloud name you entered in the system configuration) and choose the “Revert to Snapshot” action. Fill out you VM name (from vSphere) and snapshot for the basic nginx install.

– In the second one, choos your vSphere server again and choose “Power-On/Resume VM” or it’s action. Fill out the VM name again here

4. Add a “Execute shell on remote host using ssh” build step.

– Choose the SSH site you entered in the system configutation

– In the Command field enter: echo "$TEST_STRING" > /usr/share/nginx/html/index.html

Page 31: Getting Started with Jenkins: A VMWorld workshop.

31

vSphere Deployment Demo

Create a test job (cont.):

5. Add a “Execute shell” build step and enter the following in it’s Command field:curl -s http://$VSPHERE_IP | grep "$TEST_STRING”

6. Click “Save”, and the “Build with Parameters”

7. A parameter form will appear – enter some text in it (or leave the default if you wish) and click “Build”

8. While the build is running, open the console output and note that the vSphere log entries.

9. Also, if your vSphere client console is available, note the “Recent Tasks” entries that coincide.

Page 32: Getting Started with Jenkins: A VMWorld workshop.

32

vSphere Deployment Demo

Create a test job (cont.):

10. When complete, the log should show the text entered in the build parameter as being returned by the web server via the “curl” command.

– Additionally you could open a browser to the VM and see the same text.

Page 33: Getting Started with Jenkins: A VMWorld workshop.

Hints, Tips, Q&A

Page 34: Getting Started with Jenkins: A VMWorld workshop.

34

More Information

• Jenkins Home: http://jenkins-ci.org– Jenkins Documentation Wiki– Mailing Lists– IRC– Bug Tracker– Latest Jenkins CI builds and results (yes, Jenkins builds Jenkins)

• Jenkins User Conference: https://www.cloudbees.com/company/events/juc– News about upcoming conferences– Video and slides for past conferences

• Highly recommend session from 2014 SFO conference:– Seven Habits of Highly Effective Jenkins Users by Andrew Bayer

https://www.cloudbees.com/event/topic/seven-habits-highly-effective-jenkins-users-0

Page 35: Getting Started with Jenkins: A VMWorld workshop.

35

More Information

• Jenkins related Twitter feeds– @jenkinsci– @jenkinsconf– @jenkins_release– @CloudBees– @kohsukekawa

• Our Twitter feeds– Bob Webster: @rdpwebster– Eric Smalling: @ericsmalling

Page 36: Getting Started with Jenkins: A VMWorld workshop.

Q & A