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.

This commit is contained in:
2026-04-02 10:42:20 -05:00
parent da6358b63d
commit d3318deb85

15
Jenkinsfile vendored
View File

@@ -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
"""
'''
}
}
}