bmoers / sn-cicd-example-v3

Example implementation of https://github.com/bmoers/sn-cicd V3
10 stars 24 forks source link
cicd cicd-pipeline cicd-server service-now servicenow sn-cicd

Example implementation of the CICD-Server V3 for ServiceNow

Table of contents

Features

This is an example implementation of the CICD-Server for ServiceNow. It allows to send changes, captured in Update-Sets in ServiceNow, to a CICD pipeline including running ATF test cases in ServiceNow.\ Example build results:

More information about the core module can be found here https://github.com/bmoers/sn-cicd#cicd-server-for-service-now-v3

A video recording from the K18 session, where CICD-Server version 1 was presented, can be found here.

Example Pipeline

In this example you're going to:

Demo Video

A recording of this how-to can be found on YouTube:\ A recording of this how-to

Before you start

Prerequisites

Install the Scoped App

Configure the CICD-Integration in ServiceNow

Navigate to 'CICD Integration > Properties' and enable at least following:

Install the CICD-Server

cd sn-cicd-example-v3


## Configure the CICD-Server
- **Rename `example.env` to `.env`**\
    This file contains all credentials and necessary information to run the CICD-Server. Make sure you **never** commit it to a GIT repo.

> Assuming two ServiceNow environments
> - dev12345.service-now.com The Dev instance (<dev12345-dev-instance;>)
> - dev23456.service-now.com The Prod instance (<dev23456-prod-instance;>)
> 

Add following information to the .env file:

```bash
# ----- !! REQUIRED !! -----
# github credentials
CICD_PR_USER_NAME=<github-user-id>
# the github token (or password)
CICD_PR_USER_PASSWORD=<******************************>
# ServiceNow host name - this host acts as proxy to route the web hooks to the CICD-Server (via MID)
CICD_WEBHOOK_PROXY_SERVER=<dev12345-dev-instance>
# Secret (see cicd-integration properties in ServiceNow)
CICD_WEBHOOK_SECRET=5VCSj9SPRH3EbNHrBSTf
#GitHub project information
CICD_GIT_HOST=git@github.com:<github-user-id>/
CICD_GIT_URL=https://github.com/<github-user-id>/

# default git master source - let this point to production environment
CICD_GIT_MASTER_SOURCE=<dev23456-prod-instance>.service-now.com

# user to run the ATF test cases
CICD_ATF_TEST_USER_NAME=admin
CICD_ATF_TEST_USER_PASSWORD=<***********>

# user to load update-set form 'source' and 'master'
CICD_CI_USER_NAME=admin
CICD_CI_USER_PASSWORD=<***********>

# user to deploy update-set to 'target'
CICD_CD_USER_NAME=admin
CICD_CD_USER_PASSWORD=<***********>

# deployment target definition
CICD_CD_DEPLOYMENT_TARGET=<dev23456-prod-instance>.service-now.com

# ----- ** OPTIONAL ** -----
# toggle slack integration
CICD_SLACK_ENABLED=true
# webhook url
CICD_SLACK_WEBHOOK=https://hooks.slack.com/services/<********>/<********>/<*****************************>

Start the CICD-Server

In sn-cicd-example-v3 run:

npm install

and:

npm start

The web-UI is available under http://localhost:8080/ (depending of your server-options settings).\ If HTTPS is enabled you might see a "page not secure" warning. This is due to self signed certificates in this example project.\ It requires a run at least one build to display any information.

Docker

If you'd like to run the CICD-Server as a Docker container please have a look at the Dockerfile. Use Docker Compose to also start a MID server.

Trigger a CICD Run

TL;DR:

Or create the app manually:

  1. Logon to a ServiceNow instance dev12345.service-now.com (get a personal developer instance on https://developer.servicenow.com/).
  2. Create a Scoped App.\ Navigate to "System Applications > Applications" and select "New > Start from scratch". Name it "CICD Global Test App".
  3. Add some files to it like e.g business rule or script include. Use the the UI Action with the 'Box' icon to automatically comment the code.
  4. In the left navigation, open this Application definition again. "System Applications > Applications", click on "CICD Global Test App".
  5. Trigger the CICD Pipeline by just clicking on the "Build this Application [CICD]" UI Action.
  6. This will now :
    • extract the code from 'master'
    • create an 'update set' branch and extract the update set into it
    • build the app (EsLint, JsDoc, Mocha [ATF])
  7. Once all test are 'green' a pull request will be raised against master.
    • If you have Slack enabled in the configuration above you'll see corresponding messages
  8. Navigate now to GitHub, open the pull request and review the code.
  9. If you're happy with it, approve the pull request.
  10. The 'update set' branch will be merged with the 'master' branch.
  11. The application (update set) is now automatically deployed.

Contribute

If you want to contribute to this project, please fork the core project https://github.com/bmoers/sn-cicd

Project dependencies

The project is designed to use extensions. The core project (bmoers/sn-cicd) contains all 'shared' features. Customization which are dedicated to your ServiceNow environment or CICD pipeline shall be added to the 'extending' project (like this one.)

Dependencies

https://github.com/bmoers/sn-cicd-example-v3 \ --> extends
      https://github.com/bmoers/sn-cicd \       --> uses
            https://github.com/bmoers/sn-project \             https://github.com/bmoers/sn-rest-client