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:
11
Jenkinsfile
vendored
11
Jenkinsfile
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user