Jenkins Git
Jarvis Mishler

Jarvis Mishler

Intro to Jenkins CI/CD and GIT

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

Copy the DNS Name
  1. Navigate to the Azure dashboard
  2. Azure > Jenkins VM > Overview
  3. Copy DNS Name from the Overview panel
Open Port 8080
  1. Switch to the Networking tab
  2. Add a new Inbound Port for 8080
  3. Save
Change the default Jenkins URL
  1. Navigate to the Jenkins dashboard
  2. Manage Jenkins > Configure System
  3. Replace “localhost” with the copied DNS name

Make a Basic Web App

Creating a simple Web App is easy in Azure.
  1. Navigate to the Azure dashboard
  2. All Resources > Add > Web App
  3. Configure
    • App Name: must be something globally unique
    • Resource Group: can use existing or new
    • OS: Linux
    • Runtime Stack: Node.js 6.9
  4. 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.

  1. wget https://github.com/Azure-Samples/nodejs-docs-hello-world/archive/master.zip
  2. unzip master.zip
  3. cd nodejs-docs-hello-world
  4. npm install
  5. zip -r app.zip .
  6. 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

  1. Navigate to Jenkins dashboard
  2. Manage Jenkins > Manage Plugins > Available
  3. check the box for the “SiteMonitor” plugin
  4. choose Install Without Restart

Create Web Test Job

  1. New Item > Freestyle Job
  2. Enter “Web Test” for the job name
  3. Scroll to the bottom and add a Post-build Action
  4. choose Monitor Site
  5. configure the Monitor Site action
    1. URL: https://[APP-NAME].azurewebsites.net
    2. Success Codes: 200
  6. save job

Run Web Test Job

  1. click Build Now
  2. 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

Fork a Sample Repository

  1. navigate to https://github.com/Azure-Samples/nodejs-docs-hello-world/
  2. click the Fork button at the top right of screen

Create a Webhook to Jenkins

Create Webhook
  1. open Settings > Webhooks
  2. enter Jenkins receiving address
    • http://[JENKINS-DNS]:8080/github-webhook/
  3. click Update

Generate Security Credentials

Create Credential Token
  1. navigate to the Jenkins dashboard
  2. Jenkins > Manage Jenkins > GitHub
  3. Advanced > Manage Additional > Convert Login > From Login
  4. enter GitHub login information
    • Login
    • Password
  5. Create Token Credentials

Create an Automated Job

Install Azure App Services 
  1. Manage Jenkins > Manage Plugins
  2. select Available Plugins
  3. check Azure App Services
  4. choose Install Without Restart
Create a New Deploy Job
  1. Jenkins > New Item > Freestyle Job
  2. name the new job “Deploy”
  3. configure the Deploy job
    1. SCM: Git
    2. Repository URL: https://[YOUR-REPO].git
    3. Credentials: Jenkins
    4. Build Triggers: GitHub Hook
    5. Post Build Action: Publish an Azure Web App
    6. Azure Credentials: azure_service_principal
    7. Resource Group Name: [YOUR-GROUP]
    8. App Name: [APP-NAME]
    9. Source Directory: ./
  4. Save

Test Your Automation

Commit a Change
  1. navigate to your GitHub repo
  2. open the “index.js” file
  3. update the display message
    • response.end(“Hello World”);
  4. select Commit Changes
Check Jenkins for the Auto-Trigger
  1. navigate to the Jenkins dashboard
  2. watch for recent builds triggered automatically by your commit
Check Web App for New Message
  1. navigate to your Web App DNS
  2. reload the page to see your updated message

Chain Jobs Together

Add Post-build Action to Deploy Job
  1. navigate to the Jenkins dashboard
  2. select the “Deploy” job
  3. choose Configure
  4. scroll to the bottom and add a Post Build Action
  5. choose Build Other Projects in the drop down menu
  6. move the new Build Other Projects action to the bottom of the sequence
  7. configure the Build Other Projects action
    • Projects to Build: Web Test
  8. Save
Test Pipeline
  1. navigate to your GitHub repo
  2. update the display message again
  3. Commit Changes
  4. navigate back the Jenkins dashboard
  5. watch your pipeline trigger automatically
    • Deploy job –> Web Test
  6. navigate to your Web App DNS to see the result of your code change

Enjoy Your CI/CD Pipeline!

It may seem pretty basic, but what you’ve just accomplished is the fundamentals of a fully automated CI/CD pipeline. You only chained two jobs together, but Jenkins can handle chains as long as you wish, manual approval stages, code tests, security audits, notifications, etc. Check out the other plugins, look over some of the documentation, and check out more tutorials.
And feel free to reach out to the team at HATech if you have more questions or need help applying automation to enterprise scale pipelines and deployments!

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email

You must be logged in to post a comment.