Created
July 21, 2025 21:17
-
-
Save Sdy603/91556d1cb094fe972d84be7c9f4ca3f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pipeline { | |
| agent any | |
| environment { | |
| DX_API_URL = 'https://yourinstance.getdx.net/api/pipelineRuns.sync' | |
| DX_API_TOKEN = credentials('dx-api-token') // Add this as a secret text in Jenkins credentials | |
| PIPELINE_SOURCE = 'Jenkins' | |
| } | |
| stages { | |
| stage('Build') { | |
| steps { | |
| echo 'Building...' | |
| } | |
| } | |
| stage('Test') { | |
| steps { | |
| echo 'Running tests...' | |
| } | |
| } | |
| stage('Deploy') { | |
| steps { | |
| echo 'Deploying...' | |
| } | |
| } | |
| } | |
| post { | |
| success { | |
| script { | |
| // Get git commit SHA and repo | |
| def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() | |
| def repoUrl = sh(returnStdout: true, script: 'git config --get remote.origin.url').trim() | |
| def repo = repoUrl | |
| .replaceAll(/^https:\\/\\/github.com\\//, '') | |
| .replaceAll(/\\.git$/, '') | |
| .trim() | |
| // Optional: get head branch | |
| def headBranch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() | |
| // Calculate timestamps | |
| def startedAt = (currentBuild.startTimeInMillis / 1000).toLong() | |
| def finishedAt = (System.currentTimeMillis() / 1000).toLong() | |
| // Unique identifiers | |
| def pipelineName = "${env.JOB_NAME}-${env.BUILD_ID}" | |
| def referenceId = "${commitSha}-${env.BUILD_ID}" | |
| def sourceUrl = "${env.BUILD_URL}" | |
| // Send payload to DX | |
| sh """ | |
| curl -X POST ${DX_API_URL} \\ | |
| -H "Content-Type: application/json" \\ | |
| -H "Authorization: Bearer ${DX_API_TOKEN}" \\ | |
| -d '{ | |
| "pipeline_name": "${pipelineName}", | |
| "pipeline_source": "${PIPELINE_SOURCE}", | |
| "reference_id": "${referenceId}", | |
| "started_at": ${startedAt}, | |
| "finished_at": ${finishedAt}, | |
| "status": "success", | |
| "commit_sha": "${commitSha}", | |
| "repository": "${repo}", | |
| "source_url": "${sourceUrl}", | |
| "head_branch": "${headBranch}" | |
| }' | |
| """ | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment