Jenkins

DevDynamics tracks builds using post-build metadata provided through the specified curl request.

Firewall Configuration

To enable Jenkins connection to DevDynamics, permit outbound traffic for:

  • IP Address: 3.131.112.244

Prerequisites

  • To get your organization ID and API key, email: support@devdynamics.ai

CURL Request

curl --location \
 --request \
 POST 'https://api.devdynamics.ai/api/v1/deployment/<your-devdynamics-orgId>/notify' \
--header 'X-api-key: YOUR_API_KEY' \
--header 'X-delivery: BUILD_NUMBER' \
--header 'X-event: cd' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "unique-deployment-id",
    "name": "Job Name",
    "timeStamp": "2024-01-15T12:00:00Z",
    "startedAt": "2024-01-15T11:55:00Z",
    "completedAt": "2024-01-15T12:00:00Z",
    "htmlUrl": "Jenkins Build URL",
    "source": "jenkins",
    "status": "success",
    "repository": "your-repo-name",
    "artifact": "artifact-version",
    "environment": "production",
    "commit": "latest-commit-hash",        
    "tag": "test"
    "additionalInfo": {
        "label": "label1"
    },
    "stages": [{
        "name": "",
        "startTime": "",
        "endTime": "",
        "status": ""
    }]
}'

API Details

  • Endpoint: https://api.devdynamics.ai/api/v1/deployment/{your-devdynamics-orgId}/notify

  • Method: POST

  • Important Note: Request must be called in the POST-BUILD STEP of your Jenkins pipeline

Payload Fields Explanation

  • id: Unique identifier for the deployment

  • name: Name of the Jenkins job

  • timeStamp: Timestamp of the deployment event

  • startedAt: Timestamp when the deployment started

  • completedAt: Timestamp when the deployment completed

  • htmlUrl: URL to the build or deployment details

  • source: Source of the deployment (in this case, "jenkins")

  • status: Deployment status (e.g., "success", "failed")

  • repository: Name of the repository

  • artifact: Version or identifier of the deployed artifact

  • environment: Deployment environment (e.g., "production")

  • commit: Latest commit hash

  • additionalInfo: Optional additional metadata (e.g., a tag)

  • stages: Array of deployment stages with their details

  • tags: (Optional)

Sample Pipeline Script

Note: The request must be called in the POST-BUILD STEP of your Jenkins pipeline to track deployment events accurately.

pipeline {
    agent any

    environment {
        REPOSITORY = 'simple-maven-project-with-tests.git'
        ENVIRONMENT = 'Production'
    }

    stages {
        stage('Build') {
            steps {
                script {
                    git 'https://github.com/jglick/simple-maven-project-with-tests.git'
                    sh 'mvn -Dmaven.test.failure.ignore=true clean package'
                }
            }

            post {
                success {
                    script {
                        def timeStamp = new Date().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'')
                        def startTime = new Date().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'')
                        def completedTime = new Date().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'')
                        def scmVars = checkout([$class: 'GitSCM', branches: [[name: 'master']], 
                            userRemoteConfigs: [[url: 'https://github.com/jglick/simple-maven-project-with-tests.git']]])
                        
                        httpRequest contentType: 'APPLICATION_JSON', httpMode: 'POST', ignoreSslErrors: true, quiet: true, requestBody: """
                        {
                            "id": "${BUILD_NUMBER}",
                            "name": "${JOB_NAME}",
                            "timeStamp": "${timeStamp}",
                            "startedAt": "${startTime}",
                            "completedAt": "${completedTime}",
                            "commit": "${scmVars.GIT_COMMIT}",
                            "htmlUrl": "https://api.github.com/repos/devdynamics-ai/devd-client/deployments/696863512",
                            "source": "jenkins",
                            "status": "completed",
                            "repository": "${REPOSITORY}",
                            "environment": "${ENVIRONMENT}",
                            "branch": "${scmVars.GIT_BRANCH}",
                            "artifact": "",
                            "tag": "build-${BUILD_NUMBER}"
                            "additionalInfo": {},
                            "stages": [{
                                "name": "Build",
                                "startTime": "${startTime}",
                                "endTime": "${completedTime}",
                                "status": "completed"
                            }]
                        }
                        """, responseHandle: 'NONE', url: 'https://api.devdynamics.ai/api/v1/deployment/<your-devdynamics-orgId>/notify', wrapAsMultipart: false
                    }
                }
                failure {
                    script {
                        def timeStamp = new Date().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'')
                        def startTime = new Date().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'')
                        def completedTime = new Date().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'')
                        def scmVars = checkout([$class: 'GitSCM', branches: [[name: 'master']], 
                            userRemoteConfigs: [[url: 'https://github.com/jglick/simple-maven-project-with-tests.git']]])
                        
                        httpRequest contentType: 'APPLICATION_JSON', httpMode: 'POST', ignoreSslErrors: true, quiet: true, requestBody: """
                        {
                            "id": "${BUILD_NUMBER}",
                            "name": "${JOB_NAME}",
                            "timeStamp": "${timeStamp}",
                            "startedAt": "${startTime}",
                            "completedAt": "${completedTime}",
                            "commit": "${scmVars.GIT_COMMIT}",
                            "htmlUrl": "https://api.github.com/repos/devdynamics-ai/devd-client/deployments/696863512",
                            "source": "jenkins",
                            "status": "failed",
                            "repository": "${REPOSITORY}",
                            "environment": "${ENVIRONMENT}",
                            "branch": "${scmVars.GIT_BRANCH}",
                            "artifact": "",
                            "tag": "build-${BUILD_NUMBER}"
                            "additionalInfo": {},
                            "stages": [{
                                "name": "Build",
                                "startTime": "${startTime}",
                                "endTime": "${completedTime}",
                                "status": "failed"
                            }]
                        }
                        """, responseHandle: 'NONE', url: 'https://api.devdynamics.ai/api/v1/deployment/<your-devdynamics-orgId>/notify', wrapAsMultipart: false
                    }
                }
            }
        }
    }
}

Support

For any questions, contact: support@devdynamics.ai

Last updated