Jenkins
DevDynamics tracks builds using post-build metadata provided through the specified curl request.
Firewall Configuration
To enable CI/CD tools (Jenkins) connection to DevDynamics, permit outbound traffic for:
- IP Address:
3.131.112.244
Prerequisites
- Get your OrgID and API key from https://app.devdynamics.ai/settings/organisation.
- The server's IP address, where the agent will be running, must be whitelisted in Jenkins.
API Details
- Endpoint:
https://api.devdynamics.ai/api/v1/deployment/{your-devdynamics-orgId}/notify - Method: POST
- Important note: The request must be called in the post-build step of your Jenkins pipeline.
Payload fields
id: Execution ID (mandatory)name: Name of the pipeline/job (mandatory)pipelineId: Pipeline/job ID (if you don't have an ID, sendname) (mandatory)timeStamp: Timestamp of the event (mandatory)startedAt: Start timestamp when the build started (mandatory)completedAt: End timestamp when the build completed (mandatory)htmlUrl: URL to the build or deployment detailssource: Source of the deployment (for exampleJenkins)status: Deployment status (for examplesuccess,failed) (mandatory)repository: Name of the repository (mandatory)artifact: Version or identifier of the deployed artifactenvironment: Deployment environment (for exampleproduction) (mandatory forcdevents)commit: Latest commit hash (mandatory)additionalInfo: Optional additional metadata (for example a tag)stages: Array of deployment stages with their detailstags: Optional
Headers
- X-api-key: Your API key from https://app.devdynamics.ai/settings/organisation
- X-delivery: Unique execution ID
- X-event:
cdorci— usecdfor deployment,cifor build - Content-Type:
application/json
Samples
note
The request must be called in the post-build step of your Jenkins pipeline to track deployment events accurately.
cURL example
Use ci or cd for X-event as appropriate (cd for deployment, ci for build).
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-execution-id",
"name": "Job Name",
"pipelineId": "JobId",
"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": ""
}]
}'
Groovy pipeline example
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}",
"pipelineId": "${JOB_ID}",
"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}",
"pipelineId": "${JOB_ID}",
"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