From d3318deb859e592faf282326574e79db89998c7e Mon Sep 17 00:00:00 2001 From: AlexeerCT Date: Thu, 2 Apr 2026 10:42:20 -0500 Subject: [PATCH] Update Jenkinsfile to improve SSH user handling and enhance security. Replaced direct user variable with a dedicated SSH user variable and added comments to clarify the docker login process, ensuring sensitive information is not exposed. --- Jenkinsfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index afebe04c..ca8b37fd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -219,26 +219,29 @@ pipeline { steps { withCredentials([ usernamePassword(credentialsId: 'harbor-credentials', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD'), - string(credentialsId: 'dev-server-user', variable: 'DEV_SERVER_USER'), string(credentialsId: 'dev-server-host', variable: 'DEV_SERVER_HOST'), - sshUserPrivateKey(credentialsId: 'dev-server-ssh', keyFileVariable: 'DEV_SERVER_KEY') + sshUserPrivateKey( + credentialsId: 'dev-server-ssh', + keyFileVariable: 'DEV_SERVER_KEY', + usernameVariable: 'DEV_SERVER_SSH_USER' + ) ]) { script { def remote = [ name: 'dev-server', host: env.DEV_SERVER_HOST, - user: env.DEV_SERVER_USER, + user: env.DEV_SERVER_SSH_USER, identityFile: env.DEV_SERVER_KEY, allowAnyHosts: true ] - sshCommand remote: remote, command: """ + sshCommand remote: remote, command: ''' set -euo pipefail cd ~/projects/anexo76 - echo '${env.HARBOR_PASSWORD}' | docker login '${env.REGISTRY}' -u '${env.HARBOR_USERNAME}' --password-stdin + # Asume docker login ya configurado en el host destino para evitar exponer secretos por interpolación. docker compose -f docker-compose.prod.yml pull docker compose -f docker-compose.prod.yml up -d docker image prune -f - """ + ''' } } }