Refactor Jenkinsfile to improve SSH known hosts handling. Introduced a variable for the development server host and updated the known hosts file path, enhancing security and maintainability during deployment processes.

This commit is contained in:
2026-04-02 11:24:04 -05:00
parent 5c18108e79
commit 49d635b79a

11
Jenkinsfile vendored
View File

@@ -248,19 +248,20 @@ pipeline {
)
]) {
script {
def devHost = env.DEV_SERVER_HOST?.trim()
def knownHostsFile = "${env.WORKSPACE}/.jenkins-anexo76-known_hosts"
sh """
set -euo pipefail
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan -T 15 -H '${env.DEV_SERVER_HOST}' >> ~/.ssh/known_hosts
ssh-keyscan -T 15 -H '${devHost}' > '${knownHostsFile}'
"""
def remote = [
name: 'dev-server',
host: env.DEV_SERVER_HOST,
host: devHost,
user: env.DEV_SERVER_USER ?: env.DEV_SERVER_SSH_USER,
identityFile: env.DEV_SERVER_KEY,
passphrase: env.DEV_SERVER_KEY_PASSPHRASE,
allowAnyHosts: false
allowAnyHosts: false,
knownHosts: knownHostsFile
]
sshCommand remote: remote, command: '''
set -euo pipefail