GitLab Integration
Integrate ServiceNow with GitLab CI/CD pipelines for automated change management and deployment tracking
Overview
This guide shows how to integrate ServiceNow change management with GitLab CI/CD pipelines. The integration automates change request creation, approval gates, and deployment tracking directly from GitLab pipelines.
Integration Architecture
βββββββββββββββββββββββββββββββββββββββββββββββ
β GitLab CI/CD Pipeline β
β β
β ββββββββ ββββββββ ββββββββββββββββββ β
β βBuild ββββ Test ββββ Create SNOW CR β β
β ββββββββ ββββββββ ββββββββββ¬ββββββββ β
β β β
β ββββββββββββββ β
β βΌ β
β ββββββββββββββββββββ β
β β Wait for Approvalβ β
β ββββββββββ¬ββββββββββ β
β β (Poll/Webhook) β
β βΌ β
β ββββββββββββββββββββ β
β β Deploy to Prod β β
β ββββββββββ¬ββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββ β
β β Update SNOW CR β β
β ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β ServiceNow β
β Change Request β
βββββββββββββββββββββββPrerequisites
ServiceNow Setup
API Access: ServiceNow instance with REST API enabled
User Account: Service account with
itilrole for change managementOAuth Application (Recommended):
Navigate to System OAuth > Application Registry
Create new OAuth API endpoint for external clients
Note Client ID and Client Secret
GitLab Setup
CI/CD Variables (Settings > CI/CD > Variables):
SERVICENOW_INSTANCE: Your ServiceNow instance name (e.g.,dev12345)SERVICENOW_CLIENT_ID: OAuth client ID (Type: Variable, Masked)SERVICENOW_CLIENT_SECRET: OAuth client secret (Type: Variable, Masked)SERVICENOW_USERNAME: ServiceNow username (if using basic auth)SERVICENOW_PASSWORD: ServiceNow password (if using basic auth, Masked)
Repository Variables:
ASSIGNMENT_GROUP: ServiceNow assignment group nameCMDB_CI: Configuration item sys_id
Integration Method 1: REST API with cURL
Simple Change Creation
Integration Method 2: Python Script
Advanced Change Management Script
Create .gitlab/scripts/servicenow.py:
Using the Python Script
Integration Method 3: GitLab Webhooks
ServiceNow Inbound Webhook
Configure ServiceNow to receive GitLab webhook events:
ServiceNow Configuration:
Navigate to System Web Services > Scripted REST APIs
Create new API:
GitLab IntegrationCreate resource:
deployment_eventMethod: POST
Script:
GitLab Configuration:
Add webhook in Settings > Webhooks:
URL:
https://instance.service-now.com/api/x_custom/gitlab_integration/deployment_eventTrigger: Pipeline events
Enable SSL verification
OAuth 2.0 Authentication
Setup OAuth in ServiceNow
Create OAuth Application:
Navigate to System OAuth > Application Registry
Click New > Create an OAuth API endpoint for external clients
Fill in:
Name:
GitLab CI/CD IntegrationClient ID: (auto-generated, copy this)
Client Secret: (auto-generated, copy this)
Refresh Token Lifespan: 8640000 (100 days)
Access Token Lifespan: 1800 (30 minutes)
Grant Access:
Accessible from: All application scopes
Active: Yes
Use OAuth in GitLab
Best Practices
Standard Changes for Speed
Pre-approve common deployment patterns:
Error Handling and Rollback
Include Testing Evidence
Troubleshooting
Common Issues
401 Unauthorized
Check credentials in GitLab CI/CD variables
403 Forbidden
Verify ServiceNow user has itil role
Timeout waiting for approval
Increase timeout, check ServiceNow approval workflow
Change not found
Verify CHANGE_SYS_ID is passed correctly via artifacts
SSL verification failed
Update curl/Python requests, check ServiceNow SSL cert
Debug Mode
Enable detailed logging:
Next Steps
Additional Resources
Last updated