Giter VIP home page Giter VIP logo

sn-cicd-example-v3's Introduction

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:

  • extract an scoped app into a GIT repository
  • run a CICD pipeline to test the code quality, document the code and run ATF tests
  • do code review
  • raise a pull request against master (the status of the code in the production environment)
  • deploy the scoped app

As the code is stored in a GIT repo, one can also hook in other standard CICD build tools to trigger further actions like performance or UAT.
The process requires two environment. One acts as 'source' (the development environment) - one acts as 'master' and 'target' environment. This is just to simplify the demo setup.

Demo Video

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

Before you start

Prerequisites

  • Minimum 2 ServiceNow instances. 1 as DEV, 1 as PROD.
  • The Dev instance has a running and validated MID server.
  • The host of the CICD-Server (in this demo this is your PC) can be reached by the MID server.
  • A GitHub account.
  • A Access token for your this GitHub account with the privileges repo, admin:repo_hook, admin:org_hook. (Goto https://github.com/settings/tokens to configure one)
  • Git client installed and configured to connect to Github via SSH
  • The CICD Integration app installed on all ServiceNow instances.
  • ATF Test Suite Execution is enabled on all environment under 'Automated Test Framework > Administration > Properties'

Install the Scoped App

  • Install the latest version of the CICD-Integration app from GitHub on all ServiceNow environments (source and target). Alternatively you can clone the CICD-Integration repo and install the update-set from ./update_set/CICD Integration.xml.
  • On all instances configure following users: (for testing purpose you can also skip below and use the 'admin' user later in the configuration)
    • Create a CI-User account in ServiceNow and assign it to the cicd_integration_user group.
    • Create a ATF-User account in ServiceNow and assign it to the atf_test_* and impersonator groups.
    • Create a CD-User account in ServiceNow and assign it to the admin ! group

Configure the CICD-Integration in ServiceNow

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

  • CICD Integration enabled
  • Show CICD UI action in scoped apps
  • Trigger CICD process on update set 'complete'
  • Enter the CICD-Server Host Name (the host / IP of your PC). If you use Docker or have a MID server running on your PC this can be https://localhost:8443
  • Connect to CICD-Server via MID Server
  • Show JSDoc button in UI to support developer to comment code correctly
  • Pull Request Proxy switch

Install the CICD-Server

  • Get a copy of this repo:
git clone [email protected]:bmoers/sn-cicd-example-v3.git

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:

# ----- !! 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
[email protected]:<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:

  • Install the example application
  • open the App (/sys_app.do?sys_id=CICD%20Test%20Application)
  • click on "Build this Application [CICD]"

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

sn-cicd-example-v3's People

Contributors

bmoers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sn-cicd-example-v3's Issues

Build not working.

I have tried to get this working on instances running New York. The mid servers were setup using Docker and the application is running. Nothing happens when i click BUILD THIS APPLICATION from ServiceNow.

I have attached my .env file here.
neji_example.env.txt

Issue while deploying the updateset

Getting the below error message while deploying(after approving the pull request).

{"mrkdwn":true,"link_names":true,"parse":"none","attachments":[{"mrkdwn_in":["pretext","text","title","fields","fallback"],"fallback":"StatusCodeError!\n405 - {"error":{"message":"Method not Supported","detail":"GET method not supported for API"},"status":"failure"}. <Updatesetname- 1.0.0>","color":"#990016","text":"StatusCodeError!\n405 - {"error":{"message":"Method not Supported","detail":"GET method not supported for API"},"status":"failure"}. <Updatesetname- 1.0.0>","author_icon":null}],"username":"","icon_url":"","icon_emoji":""}

I will send the complete log and .env file by email.

Pull request not triggering

Thanks for creating the server and making it opensource :)
I am Trying to build the application, but the pull request is not triggering.
The logs says "master is not enabled, Skip export." Could you please point out what could be the reason for this.
Thanks!!
tempsnip

Getting error while pushing data to GIT

'Command failed: git add "C:\Users\SHUVAR1\AppData\Local\Temp\git-root\5ab205bc-8f74-4cd1-800c-a3aeaa96367b\us\global\sys_update_set_76658483dbd37300e76e771c8c9619c3.xml"\nfatal: C:\Users\SHUVAR1\AppData\Local\Temp\git-root\5ab205bc-8f74-4cd1-800c-a3aeaa96367b\us\global\sys_update_set_76658483dbd37300e76e771c8c9619c3.xml: 'C:\Users\SHUVAR~1\AppData\Local\Temp\git-root\5ab205bc-8f74-4cd1-800c-a3aeaa96367b\us\global\sys_update_set_76658483dbd37300e76e771c8c9619c3.xml' is outside repository\n'

Getting above error when trying to push the data from update set to GIT through CICD.

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

When I run example background script exactly as explained, I get following error

request ended in error - StatusCode 0, ResponseMessage: The request failed: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure, Endpoint: https://:4443/run, RequestBody: [object Object]: no thrown error

Not sure whats going on wrong!

RestClient post payload to the /run rest api, server console got error 'CICD.prototype.addStep Error: addStep, no run instance found. State: run.run : failed'

Post a json payload to https://localhost:8443/run, client got 200 ok, but server console log show a lot of error

curl -X POST -k -H 'Content-Type: application/json; charset=utf-8' -H 'x-access-token: 1Tnt2bx9mrVjxMQDfjhvRAYxiL9ldQN5ITR6DtM8T6Pq8YLbEjwAd60vmUiTIvSE' -i https://localhost:8443/run --data '{
    "requestor": {
        "userName": "BC",
        "fullName": "BC",
        "email": "[email protected]"
    },
    "updateSet": "87294fd0dbb12300f526d426ca961912",
    "application": {
        "id": "51s3foc6of5skpulzc6bidvn5c89xrp4",
        "name": "SN Application Name"
    },
    "git": {
        "repository": "sn-example",
        "remoteUrl": "https://github.com/gitlabbin/sn-example.git",
        "url": "https://github.com/gitlabbin/sn-example.git",
        "enabled": true,
        "pullRequestEnabled": true
    },
    "atf": {
        "updateSetOnly": false
    },
    "source": {
        "name": "https://dev59944.service-now.com/",
        "accessToken": "eXwdKi7z6OEkRYh9ljJNY7271S9jnJxyyyk0VmMQJFJejbG601A3jjMFQZDLcoruelEtxXffSSPZX7PDIc43wQ"
    },
    "master": {
        "name": null,
        "accessToken": null
    }
}'

Server console failed: "Requested URI does not represent any resource: /swre/cicd/updateset/87294fd0dbb12300f526d426ca961912",

[09:29:53.140] [ERROR] [19324]  CICD.prototype.addStep Error: addStep, no run instance found. State: run.run : failed
    at Promise.try (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/sn-cicd/lib/cicd.js:427:23)
    at tryCatcher (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/method.js:39:29)
    at CICD.addStep (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/sn-cicd/lib/cicd.js:422:27)
    at step (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/sn-cicd/lib/modules/run.js:22:21)
    at Promise.try.then (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/sn-cicd/lib/modules/run.js:56:20)
    at tryCatcher (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/promise.js:606:10)
    at Async._drainQueue (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/brianchen/my-wk/sn-cicd-example-v3/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate (timers.js:632:19)
[09:29:53.174] [ERROR] [19324]  { name: 'StatusCodeError',
  statusCode: 400,
  message:
   '400 - {"error":{"message":"Requested URI does not represent any resource: /swre/cicd/updateset/87294fd0dbb12300f526d426ca961912","detail":null},"status":"failure"}',
  error:
   { error:
      { message:
         'Requested URI does not represent any resource: /swre/cicd/updateset/87294fd0dbb12300f526d426ca961912',
        detail: null },
     status: 'failure' }

issue related to slack

[19:00:21.580] [LOG] [21292] [/worker#p3KpAwKZO0cgPVPBAAAB] build-project : cleaning up project
[19:00:21.599] [LOG] [21292] deleting C:\temp\repos\accdab5f-bbfb-419a-869f-6c5b1ca9f72c\node_modules
[19:00:22.008] [LOG] [5504] Slack not active. Message: {"mrkdwn":true,"link_names":true,"parse":"none","attachments":[{"mrkdwn_in":["pretext","text","title","fields","fallback"],"fallback":"Build for https://localhost:8443/goto/run/CkZ26mocOh5OHKsj|CICDIntegrationB3 did not pass!","color":"#990016","text":"Build for https://localhost:8443/goto/run/CkZ26mocOh5OHKsj|CICDIntegrationB3 did not pass!","author_icon":null}],"username":"","icon_url":"","icon_emoji":""}
[19:00:22.053] [LOG] [27024] /worker#OI3n4tjh-nBXBHEzAAAC is done (/worker/done) with job: efea6fcf-5203-4077-b2b0-80cc18d22de3 Type: exe
[19:00:35.662] [LOG] [27024] /worker#p3KpAwKZO0cgPVPBAAAB is done (/worker/done) with job: ef7eaeb4-7c3b-4879-9fb9-7d99f7cfff1a Type: exe
[19:00:35.691] [LOG] [27024] /worker#PVnGN9iMei_Fmi0CAAAA is done (/worker/done) with job: a6b3bf47-370c-4e8c-baba-7c652316a155 Type: undefined

Hi boris,
I am facing this issue related to slack not active, Could you please suggest how to resolve this issue
Thanks
Tanoy

project-template gulpfile.js need support git disabled updateset

In sn-cicd v3, allows disable git via CICD_GIT_ENABLED=false,
but only one gulpfile template sn-cicd/lib/project-templates/gulpfile.js for build, so it will fail the job.

Better provide two templates:

  • gulpfile.git.js
  • gulpfile.nogit.js

Need enhancement while copy the template file to repo, if git disabled then use an other gulpfile.

Thanks

Getting issue while running ATF through CICD pipeline

Facing below issue while running the ATF test case through CICD pipeline-

TypeError: describe is not a function
at Object. (C:\temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\test\atf-wrapper.js:62:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\mocha.js:334:36
at Array.forEach ()
at Mocha.loadFiles (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\mocha.js:331:14)
at Mocha.run (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\mocha.js:811:10)
at Object.exports.singleRun (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\cli\run-helpers.js:108:16)
at exports.runMocha (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\cli\run-helpers.js:142:13)
at Object.exports.handler.argv [as handler] (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\cli\run.js:292:3)
at Object.runCommand (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\lib\cli\cli.js:68:6)
at Object. (C:\Temp\repos\ad8a6168-156f-46b6-9cb2-58c11c145e90\node_modules\mocha\bin\mocha:154:29)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.