Linking a ServiceNow app to GitHub (Part 1)


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 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 so 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
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

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

Docs:

Linking A Studio App to GitHub

Comments

Popular Posts