ci and cd using jenkins and azure devops

A node js application example where CI is done by Jenkins and CD is done by Azure devops. Build is getting generated by Jenkins and artifacts is given to Azure devops for deployment.

Requirements

Create an Azure DevOps Organization

  • In the top left, click on the hamburger menu, and select All services.
  • In the All services search box, type “azure devops”.
  • Select Azure DevOps organizations.
  • Click the link for My Azure DevOps Organizations.
  • Choose your region, and click Continue.
  • Click Create new Organization.
  • Keep clicking Continue until you reach the page to set up your project.
  • In Project Name, name your project MyFirstProject.
  • Click Create Project.

Create the Jenkins CI Build

  • Copy the forked page’s URL (it will contain your GitHub username), return to your Jenkins browser tab, and paste the URL into the Repository URL field.
  • In Branch Specifier, enter */jenkins.
  • Under Build, click Add build step, and select Execute shell from the dropdown menu.
  • In the Command field, enter:
    npm install
    zip -r archive.zip node_modules package.json server.js
  • Under Post-build Actions, click Add post-build action, and select Archive the artifacts from the
  • the dropdown menu.
  • In Files to archive, enter archive.zip.
  • Click Save.
  • On the left-hand menu, select Build now.
  • In the lower left, click on your build, which should appear as #1.
  • On the left-hand menu, click Console Output.
  • Go back to your browser tab with the MyFirstProject page in Azure DevOps, and click Project Settings in the lower left-hand corner.
  • On the left side, under Pipelines, click Service connections.
  • Click Create service connection.

 Create Azure DevOps CD Pipeline

  • On the New service connection menu, select Azure Resource Manager. Then, click Next.
  • Select Service principal (manual), and then click Next.
  • Return to your main Azure portal browser tab, and open Cloud Shell by clicking on the icon immediately to the right of the search bar (looks like a caret (>) inside of a square).
  • Select PowerShell.
  • Click Show advanced settings.
  • For Storage account, click Use existing.
  • For Cloud Shell region, use the region where your cloud resources are deployed.
  • To check this, click the hamburger menu on the top left of the Azure portal.
  • Select All resources.
  • Review the Location column to see the region where your resources are deployed. Use this for the region in the Cloud Shell.
  • Under File share, select Create new, and type fileshare.
  • Click Create storage.
  • Create Azure Service Connection
  • Once you are connected to the Cloud Shell, get the subscription ID:
  • Get-AzSubscription
  • Copy the subscription ID under Id.
  • Return to your browser tab with the Project Settings Azure DevOps page, and paste the subscription ID into the field under Subscription Id (in the New Azure service connection pane).
  • Back in PowerShell, copy the subscription name under Name.
  • In the Service connection name field, name the service connection SP for service principal.
    Click Verify and save.

Create Jenkins Service Connection

  • In the top right-hand corner, click New service connection.
  • Select Jenkins, and click Next.
  • Paste the root Jenkins URL you copied and saved to a text file at the beginning of the lab into the Service URL field.
  • Click the checkbox for Accept untrusted SSL certificates.
  • For Username, enter cloud_user, and type in the password you created while setting up the Jenkins installation.
  • Click Verify to make sure verification succeeded.
  • Under Service Connection Name, enter Jenkins.
  • Click Verify and save

Create the Azure DevOps CD pipeline

  • On the left-side menu, select Pipelines.
  • Select Releases.
  • Click New pipeline.
  • Under Select a template, click Empty job, and then Apply.
  • Click Add an artifact.
  • In the Add an artifact pane, click 5 more artifact types.
  • Select Jenkins from the artifact types.
  • In the Service connection dropdown menu, select Jenkins.
  • In the Jenkins Job dropdown, select nodejs.
  • Click Add.
  • Under Stage 1, click the 1 job, 0 task link.
  • In the search bar of the Add tasks pane, type Azure web.
  • Select Azure Web App, and click Add.
  • Click the Azure Web App Deploy tile, and set the following values:
  • Azure subscription: SP
  • App type: Web App on Linux
  • App name: Select the only app name that’s available
  • Click Save near the top right.
  • Click OK.
  • Near the top right, next to Save, click Create release.
  • Under Artifacts, select the only available version.
  • Click Create.
  • In the green bar on the top, click the link for Release-1.
  • Under the Stage 1 box, click Logs to view the progress.
  • Wait until the Azure web application has successfully deployed. This may take several minutes.
  • Return to your main Azure portal tab, and click on the hamburger menu in the upper left-hand corner.
  • Select App Services.
  • Select the application created.
  • Under Essentials, click the URL to open the Node.js web application.

Leave a Reply