Download: HATech Academy – Intro to Jenkins & Git PDF
Watch the training video here:Create a Jenkins Server
Follow the steps in This Link for a straightforward guide to spinning up a Jenkins server using an Azure Blueprint.
Once Jenkins is up and running, continue to the steps below.
Open Jenkins to the Web
- Navigate to the Azure dashboard
- Azure > Jenkins VM > Overview
- Copy DNS Name from the Overview panel
- Switch to the Networking tab
- Add a new Inbound Port for 8080
- Save
- Navigate to the Jenkins dashboard
- Manage Jenkins > Configure System
- Replace “localhost” with the copied DNS name
Make a Basic Web App
- Navigate to the Azure dashboard
- All Resources > Add > Web App
- Configure
- App Name: must be something globally unique
- Resource Group: can use existing or new
- OS: Linux
- Runtime Stack: Node.js 6.9
- Create
Hello World!
Azure Cloud Shell is a great way to interact with Azure. Since you activate it within the Azure dashboard, it’s already authenticated against your Azure subscription so there’s no need to login.
Deploy Code
Use Cloud Shell to deploy code into your Web App with the following commands.
- wget https://github.com/Azure-Samples/nodejs-docs-hello-world/archive/master.zip
- unzip master.zip
- cd nodejs-docs-hello-world
- npm install
- zip -r app.zip .
- az webapp deployment source config-zip –resource-group [GROUP] –name [APP-NAME] –src app.zip
Open the App
Navigate to “https://[APP-NAME].azurewebsites.net/” to check your code
Create a HTTP Check
A simple HTTP check plugin allows us to easily create our first Test Job.
Install SiteMonitor Plugin
- Navigate to Jenkins dashboard
- Manage Jenkins > Manage Plugins > Available
- check the box for the “SiteMonitor” plugin
- choose Install Without Restart
Create Web Test Job
- New Item > Freestyle Job
- Enter “Web Test” for the job name
- Scroll to the bottom and add a Post-build Action
- choose Monitor Site
- configure the Monitor Site action
- URL: https://[APP-NAME].azurewebsites.net
- Success Codes: 200
- save job
Run Web Test Job
- click Build Now
- click Site Monitor to view the test result
Get into GitHub
Sign In or Sign Up
- Option A
- sign into an existing GitHub account
- Option B
- sign up for a free account at https://github.com/
Fork a Sample Repository
- navigate to https://github.com/Azure-Samples/nodejs-docs-hello-world/
- click the Fork button at the top right of screen
Create a Webhook to Jenkins
- open Settings > Webhooks
- enter Jenkins receiving address
- http://[JENKINS-DNS]:8080/github-webhook/
- click Update
Generate Security Credentials
- navigate to the Jenkins dashboard
- Jenkins > Manage Jenkins > GitHub
- Advanced > Manage Additional > Convert Login > From Login
- enter GitHub login information
- Login
- Password
- Create Token Credentials
Create an Automated Job
- Manage Jenkins > Manage Plugins
- select Available Plugins
- check Azure App Services
- choose Install Without Restart
- Jenkins > New Item > Freestyle Job
- name the new job “Deploy”
- configure the Deploy job
- SCM: Git
- Repository URL: https://[YOUR-REPO].git
- Credentials: Jenkins
- Build Triggers: GitHub Hook
- Post Build Action: Publish an Azure Web App
- Azure Credentials: azure_service_principal
- Resource Group Name: [YOUR-GROUP]
- App Name: [APP-NAME]
- Source Directory: ./
- Save
Test Your Automation
- navigate to your GitHub repo
- open the “index.js” file
- update the display message
- response.end(“Hello World”);
- select Commit Changes
- navigate to the Jenkins dashboard
- watch for recent builds triggered automatically by your commit
- navigate to your Web App DNS
- reload the page to see your updated message
Chain Jobs Together
- navigate to the Jenkins dashboard
- select the “Deploy” job
- choose Configure
- scroll to the bottom and add a Post Build Action
- choose Build Other Projects in the drop down menu
- move the new Build Other Projects action to the bottom of the sequence
- configure the Build Other Projects action
- Projects to Build: Web Test
- Save
- navigate to your GitHub repo
- update the display message again
- Commit Changes
- navigate back the Jenkins dashboard
- watch your pipeline trigger automatically
- Deploy job –> Web Test
- navigate to your Web App DNS to see the result of your code change