Update Push to Registry stage with secure credentials handling for DigitalOcean
Some checks failed
DevSecOps-Multibranch/pipeline/head There was a failure building this commit
Some checks failed
DevSecOps-Multibranch/pipeline/head There was a failure building this commit
This commit is contained in:
19
Jenkinsfile
vendored
19
Jenkinsfile
vendored
@@ -42,10 +42,21 @@ pipeline {
|
||||
|
||||
stage('Push to Registry') {
|
||||
steps {
|
||||
script {
|
||||
echo "Pushing images to DigitalOcean..."
|
||||
sh "docker push ${REGISTRY_URL}/${REPO_NAME}:${BACKEND_TAG}"
|
||||
sh "docker push ${REGISTRY_URL}/${REPO_NAME}:${FRONTEND_TAG}"
|
||||
// Securely inject the token into the script
|
||||
withCredentials([string(credentialsId: 'do-registry-token', variable: 'DO_TOKEN')]) {
|
||||
script {
|
||||
echo "Logging into DigitalOcean Registry..."
|
||||
|
||||
// Explicit Login: Uses the token as both user and password (DO Standard)
|
||||
sh 'echo $DO_TOKEN | docker login registry.digitalocean.com -u $DO_TOKEN --password-stdin'
|
||||
|
||||
echo "Pushing images..."
|
||||
sh "docker push ${REGISTRY_URL}/${REPO_NAME}:${BACKEND_TAG}"
|
||||
sh "docker push ${REGISTRY_URL}/${REPO_NAME}:${FRONTEND_TAG}"
|
||||
|
||||
// Cleanup: Logout to keep the agent secure
|
||||
sh 'docker logout registry.digitalocean.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user