Created
July 3, 2025 17:24
-
-
Save Sdy603/6f77bb127857d7da8c98d987a09b959b 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 { | |
| API_TOKEN = credentials('DX_DEPLOYMENT_API_TOKEN') // Jenkins credential ID | |
| DATACLOUD_HOST = 'yourinstance.getdx.net' | |
| SERVICE_NAME = 'my_service' | |
| } | |
| options { | |
| timestamps() | |
| } | |
| stages { | |
| stage('Checkout') { | |
| steps { | |
| checkout scm | |
| } | |
| } | |
| stage('Register Deployment') { | |
| when { | |
| branch 'main' // Adjust as needed | |
| } | |
| steps { | |
| script { | |
| def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() | |
| def repo = env.GIT_URL.replaceFirst(/^.*github.com[/:]/, '').replaceAll(/\.git$/, '') | |
| def deployedAt = sh(script: 'date -u +"%Y-%m-%dT%H:%M:%SZ"', returnStdout: true).trim() | |
| def payload = """{ | |
| "reference_id": "${env.BUILD_ID}", | |
| "deployed_at": "${deployedAt}", | |
| "service": "${env.SERVICE_NAME}", | |
| "commit_sha": "${commitSha}", | |
| "repository": "${repo}" | |
| }""" | |
| def responseCode = sh( | |
| script: """ | |
| curl -s -o response.txt -w "%{http_code}" -X POST https://${DATACLOUD_HOST}/api/deployments.create \\ | |
| -H "Authorization: Bearer ${API_TOKEN}" \\ | |
| -H "Content-Type: application/json" \\ | |
| -d '${payload}' | |
| """, returnStdout: true | |
| ).trim() | |
| if (responseCode != '200') { | |
| def errorMessage = sh(script: "jq -r '.message' response.txt", returnStdout: true).trim() | |
| def errorType = sh(script: "jq -r '.error' response.txt", returnStdout: true).trim() | |
| error "DX API error (${responseCode}): ${errorType} - ${errorMessage}" | |
| } else { | |
| echo "DX deployment registered successfully." | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment