pipeline {
agent any
environment {
CTRLPLANE_API_KEY = credentials('ctrlplane-api-key')
DEPLOYMENT_ID = 'your-deployment-id'
}
stages {
stage('Build') {
steps {
sh 'docker build -t myapp:${GIT_COMMIT} .'
sh 'docker push myapp:${GIT_COMMIT}'
}
}
stage('Create Version') {
steps {
script {
def response = httpRequest(
url: "https://app.ctrlplane.dev/api/v1/deployments/${DEPLOYMENT_ID}/versions",
httpMode: 'POST',
customHeaders: [
[name: 'Authorization', value: "Bearer ${CTRLPLANE_API_KEY}"],
[name: 'Content-Type', value: 'application/json']
],
requestBody: """{
"tag": "${GIT_COMMIT}",
"name": "Build #${BUILD_NUMBER}",
"status": "ready",
"metadata": {
"commit": "${GIT_COMMIT}",
"branch": "${GIT_BRANCH}",
"build_url": "${BUILD_URL}"
}
}"""
)
}
}
}
}
}