Search for answers or browse our knowledge base.
Create an Entity
Overview
Use the following procedure to create an entity to any work system with SyncNow DevOps Gate . We have created groovy scripts for Jenkins, or you can copy paste curl commands from our user interface from DevOps Gate project configuration.
Usage Examples
- Creating a bug when automated testing has failed
- Creating a bug when security vulnerability has found
- Creating a service ticket when an incident is found in another system
Create an Entity
This procedure creates an Entity accordingly to mapping definition. SyncNow will update existing entity if has the same title/summary or with a filtered defined
Request
The request URL should contains the system ID, this can be copied from the DevOps Process definition page
POST /api/v1.0/DevOpsGate/Enrich/{DevOpsProjectID}?action=create
The payload contains the parameters as defined in the DevOps Gate Process and their values, below the parameters defined for the example request
Parameter | Description |
---|---|
Param1…ParamX | Parameters as defined in the DevOps Gate per entityTyoe mapping |
subProject | The target work system project as defined in the DevOps Gate Process. Work systems for publishing can be limited through SyncNow DevOps Process configuration |
entityType | The entity to be created |
[
{
"fields": [
{
"key": "Param1",
"value": "string"
},
{
"key": "Param2",
"value": "string"
},
{
"key": "Param3",
"value": "string"
}
],
"subProject": "MyProject",
"entityType": "Bug"
}
]
Response
Parameter | Description |
---|---|
SystemID | The System where the entities were created |
EntitiesID | The entities ids created |
Error | Errors which has occurred during the creation process |
Warning | Warnings which has occurred during the creation process |
{ "updatedEntitiesID": [ { "systemID": "10", "entityKeys": [ "CLS-3938" ] } ], "errors": [], "warnings": [] }
Jenkins Groovy Script
The script below is a groovy code example which creates an entity with SyncNow DevOps Gate
@NonCPS
def getCommentsString() {
def list = []
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
if (entry.msg != null) {
list.add("""${entry.commitId} on ${new Date(entry.timestamp)}: ${entry.msg.replaceAll("[\n\r]", " ")}""")
}
}
}
return list.join(',')
}
pipeline {
agent any
stages {
stage('Clone') {
steps {
echo 'Clone Code'
}
}
stage('Version') {
steps {
echo 'Version'
}
}
stage('Test') {
steps {
echo 'Test'
}
}
stage('Build') {
steps {
echo 'Build'
}
}
stage('Publish') {
steps {
echo 'Publish'
}
}
stage('Notify SyncNow') {
steps {
echo 'Notify'
echo "Job Name is ${JOB_NAME}, Build ID is ${env.BUILD_ID}"
script {
def commits = getCommentsString()
def payload = """
[
{
"fields": [
{
"key": "Param1",
"value": "string"
},
{
"key": "Param2",
"value": "string"
},
{
"key": "Param3",
"value": "string"
}
],
"subProject": "MyProject",
"entityType": "Bug"
}
]
"""
// Create entities and update entities from commit. Result in format for adding attachments
string response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', authentication: 'SyncNow', requestBody: "${payload}", url: "https://<SyncNowBaseURL>/api/v1.0/app/DevOpsGate/Enrich/<DevOpsProjectID>?action=create"
println("Status: ${response.status}")
println("Content: ${response.content}")
}
}
}
}
}
Step By Step Instructions
Example. Create If… and Update an Entity action
- Create a DevOps Gate Process
- Navigate to the Mapping Entities page
- Navigate to the Mapping Options page for specific entities map
- Add filters – in the below example we added a filter by Status
Duplicate Detection
Entity names are always checked by their summary | Title. If an entity with the same name | title and type will be found, it will be updated
- Go to the DevOps Gate Process Configuration and press the How It Works link
- Select
Create & Update Entities from Commits
- Copy CURL
- Paste into a Command Line. Set correct sub-project where to create an entity and execute
- Lets change a bit a content of fields end execute again
- A new entity has been create with info about both DevOps Gate calls
- Lets change the status of the entity
- And execute CURL again: new entity has been created