Linking a ServiceNow app to GitHub


Linking a ServiceNow app to GitHub

Here's an example of using Studio's source control integration to track your ServiceNow application development via GitHub.

Create GitHub Repository

In your GitHub account:

  • Navigate to the Repositories page
  • Click New & provide a meaningful Repository name
  • Select Public or Private as applicable
  • Click Create Repository
  • Copy the SSH URL into your clipboard

Create Scoped App in ServiceNow

Create your scoped app via Studio or App Engine Studio.

Create Credentials

After creating your scoped app in Studio, you have to add a credential to your ServiceNow instance so it can perform actions in your GitHub repositories.

But before that, you need to add an SSH key to your GitHub account.

In your GitHub account

  • Navigate to Profile > Settings
  • Click SSH and GPG keys on the left navigation bar (under Access category)
  • Click New SSH key
  • Navigate to this website: https://8gwifi.org/sshfunctions.jsp
  • Select:
    • SSH-Keygen Online Algorithm: ECDSA
    • RSA Key Size: 521
  • Add Passphrase
  • PrivateKey/PublicKey will automatically be generated
  • Go back to the New SSH key page 
  • Title - assign a meaningful name
  • Paste the Public Key from the website above into the Key field
  • Click Add SSH key
For more info, refer to this doc

PS. This combo works fine and is recommended to link a custom app to a GitHub repo. Of course, you can also use the Basic Auth Credentials method. However, this method is not secure. Check out this tutorial or this one if you would still like to link your app to a GitHub repo with the Basis Auth Credentials method.

In your ServiceNow instance:

  • Navigate to Connections & Credentials > Credentials
  • Click New
  • Select SSH Private Key Credentials
  • Populate the following fields:
    • Name - assign a meaningful name
    • User name - your GitHub username
    • Password - your GitHub password
    • SSH passphrase - the same passphrase you have added above (when generating the SSH Key)
    • SSH Private Key - must contain the Private Key contents corresponding to the key you created/added to GitHub above
  • Click Submit
To see if you have successfully connected the app to your GitHub repo, navigate to your GitHub repo and verify the initial commit:

  • Click Compare & pull request (This step can be performed only after you have linked the scoped app to GitHub source control)
Note: You don't get this message when using the Basic Auth Credentials method.

Link to Source Control

In your ServiceNow instance:
  • Navigate to your scoped application in Studio
  • Select Source Control > Link to Source Control
  • Populate the resulting dialog box as follows:
    • Network protocol: select ssh
    • URL: paste the URL from GitHub here
    • Branch: generally, the default is good here; if you have an alternate branch naming you want to use, update as applicable
    • MID Server Name: If you are segregating MID server usage, select a MID with access to GitHub here
    • Credential: select the credential you added above
  • Click Link to Source Control
  • Verify the operation is successful; if you do not see success, it is usually helpful to set MID logging to the maximum and retry the operation.  Common issues are network connectivity or GitHub permissions.

If you are getting the dreaded Repository authentication failed error message, then this might be the solution you are looking for. Alternatively, this post might be helpful too. 


Resources:

  • Tutorials:

ServiceNow: Link to GitHub Source control [via SSH Private Key Credentials]

Note: RSA type key (instead of ECDSA) works best.

Servicenow Github Integration - Saving application using source control [via Basic Auth Credentials]

How I Ditched Update Sets for GitHub in ServiceNow

Github Connection with ServiceNow Source Control

Note: in this tuto you can learn how to work with branches, etc.

  • Articles:

How to Set or Change ServiceNow Application's Repository URL, Credentials, or SSH Key

  • Docs:

Linking A Studio App to GitHub

Ditch Update Sets for GitHub in ServiceNow

Good Practice

"When you create something in ServiceNow (that could be a catalog item, flow, playbook, etc.), think about creating it in an application. Stop using Global scope; stop using customized update sets... Pull yourself separately enough away from the OOTB. Yes, there are use cases for using the OOTB apps and customized update sets, but they are few. So, when you're creating, think about first creating an app, and don't worry about creating an update set."

Source

Creating applications in ServiceNow is better than using global scope and customized update sets. Some reasons why I think so:

  • It allows you to separate your customizations from the out-of-the-box functionality
  • It enables you to use version control and branching for your changes
  • It makes it easier to deploy and test your changes across different environments

So, create an app first. Link it to a source control platform. Then you can create branches for each configuration or customization in your application and commit the changes to the source control whenever you are ready.

That's a wrap!

What do you think? Do you have any tips or best practices for creating applications in ServiceNow?

Comments

Popular Posts