How Can We Help?

Search for answers or browse our knowledge base.

Deployment | Administration | Support

< All Topics
Print

Update Entity From Code Commits

Overview

Below is the process for updating and entity in target work systems by requests and a code commit to SyncNow DevOps Gate APIs. For the update to work developers need to mention work system entities in their code commit comment with #{target work system ID}

We have also created groovy scripts for Jenkins, or you can copy paste curl commands from our user interface from DevOps Gate project configuration.

Update Entities From Code Commits with Comment

Updates entities, that are mentioned in a comment of all commits of a build

Usage Examples

A comment of a commit may look like the following Done some fixes to code #ENT-1, #ENT-2. After build will be created entities ENT-1 and ENT-2 will be updated accordingly to the mapping definition.

  1. Update an entity with build | deploy version number
  2. Update an entity if the latest build has failed
  3. Link Build to an entity – the build details and URL are set in the entity comment

Request

POST /api/v1.0/DevOpsGate/Enrich/{DevOpsProjectID}?action=update

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 Entity Type mapping
entityUniqueKeyOptional if it is needed to update an entity without the use of comments
commentsThe comments with #{Entity ID}
[
    {
        "fields": [
            {
                "key": "Param1",
                "value": "string"
            },
            {
                "key": "Param2",
                "value": "string"
            },
            {
                "key": "Param3",
                "value": "string"
            }
        ],       
        "comments": "String with entities unique identifiers from the target system to add comments or remote link. For example, this is a comment in some commit. Need to update entities #CLS-3938, #CLS-3933"
    }
]

Response

ParameterDescription
updatedEntitiesIDList of Updated entity IDs
systemIDThe target system id where entities updated
entityKeysThe updated entities keys
ErrorErrors which has occurred during the update process
WarningWarnings which has occurred during the update process
{
    "updatedEntitiesID": [
        {
            "systemID": "10",
            "entityKeys": [
                "CLS-3933",
                "CLS-3938"
            ]
        }
    ],
    "errors": [],
    "warnings": []
}

Jenkins Script

This Jenkins script takes all comments with entity ids mentioned in commits joins them and add them as one comment to be updated to target system, then it uses SyncNow DevOps Gateway to update all entities in the commit.

@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"
			}
		],
		"comments": "${commits}"
	}
]
                    """

                    // 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=update"


                    println("Status: ${response.status}")
                    println("Content: ${response.content}")
                }
            }
        }
    }
}

Step By Step Instructions

  1. Create a DevOps Gate Process
  2. Add one more entity type mapping and set any fields mapping to it
w1.jpg
  1. Create 2 entities in a target system that should be updated by the DevOps Gate
  1. Go to the DevOps Gate Process Configuration and press the How It Works link
  1. Select Update Entities from Commits
  2. Copy CURL
  1. Paste into a Command Line. Set entities keys of the entities created upper and execute
  1. Entities has been updated accordingly to the mapping definition
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 an Entity
Next Upload Attachments to Entities
Table of Contents