How Can We Help?

Search for answers or browse our knowledge base.

Deployment | Administration | Support

< All Topics
Print

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

  1. Creating a bug when automated testing has failed
  2. Creating a bug when security vulnerability has found
  3. 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

ParameterDescription
Param1…ParamXParameters as defined in the DevOps Gate per entityTyoe mapping
subProjectThe target work system project as defined in the DevOps Gate Process. Work systems for publishing can be limited through SyncNow DevOps Process configuration
entityTypeThe entity to be created
[
  {
    "fields": [
      {
        "key": "Param1",
        "value": "string"
      },
      {
        "key": "Param2",
        "value": "string"
      },
      {
        "key": "Param3",
        "value": "string"
      }
    ],
    "subProject": "MyProject",
    "entityType": "Bug"    
  }
]

Response

ParameterDescription
SystemIDThe System where the entities were created
EntitiesIDThe entities ids created
ErrorErrors which has occurred during the creation process
WarningWarnings 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

  1. Create a DevOps Gate Process
  2. Navigate to the Mapping Entities page
  3. Navigate to the Mapping Options page for specific entities map
  1. 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
  1. Go to the DevOps Gate Process Configuration and press the How It Works link
  1. Select Create & Update Entities from Commits
  1. Copy CURL
  1. Paste into a Command Line. Set correct sub-project where to create an entity and execute
  1. Lets change a bit a content of fields end execute again
  1. A new entity has been create with info about both DevOps Gate calls
  1. Lets change the status of the entity
  1. And execute CURL again: new entity has been created
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Previous Create DevOps Gate Process
Next Update Entity From Code Commits
Table of Contents