fix jenkinsfile

This commit is contained in:
mpavlov
2024-09-29 01:50:06 +03:00
parent 42a176bd7c
commit e3ca04efd0

31
Jenkinsfile vendored
View File

@@ -1,17 +1,22 @@
pipeline { pipeline {
agent any agent any
options {
buildDiscarder logRotator (
numToKeepStr: '5',
daysToKeepStr: '7',
artifactNumToKeepStr: '10',
artifactDaysToKeepStr: '7'
)
}
parameters { parameters {
string(name: "target_host", defaultValue: "", trim: true, description: "Target host") string(name: "target_host", defaultValue: "", trim: true, description: "Target host")
string(name: "username", defaultValue: "", trim: true, description: "Ansible user")
password(name: "password", defaultValue: "", description: "Ansible password")
booleanParam(name: "rproxy_install", defaultValue: true, description: "Install Rproxy") booleanParam(name: "rproxy_install", defaultValue: true, description: "Install Rproxy")
base64File(name: "rootca", description: "RootCA (only for 'Install Rproxy')") base64File(name: "rootca", description: "RootCA (only for 'Install Rproxy')")
base64File(name: "rootca_key", description: "RootCA key (only for 'Install Rproxy')") base64File(name: "rootca_key", description: "RootCA key (only for 'Install Rproxy')")
booleanParam(name: "config_add", defaultValue: true, description: "Add config") booleanParam(name: "config_add", defaultValue: true, description: "Add config")
string(name: "rproxy_service_name", defaultValue: "", trim: true, description: "Service name, ex. jenkins (for 'Add config' job only)") string(name: "rproxy_service_name", defaultValue: "", trim: true, description: "Service name (for 'Add config' job only)")
string(name: "rproxy_service_port", defaultValue: "", trim: true, description: "Service port (for 'Add config' job only)") string(name: "rproxy_service_port", defaultValue: "", trim: true, description: "Service port (for 'Add config' job only)")
string(name: "rproxy_service_address", defaultValue: "", trim: true, description: "Service address (for 'Add config' job only)") string(name: "rproxy_service_address", defaultValue: "", trim: true, description: "Service address (for 'Add config' job only)")
} }
stages { stages {
stage('Save certs') { stage('Save certs') {
@@ -37,8 +42,13 @@ pipeline {
} }
steps { steps {
script { script {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: params.password]]]) { withCredentials([
sh 'ansible-playbook rproxy.yml -i ${target_host}, -t install -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'),
usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password')
]) {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) {
sh 'ansible-playbook rproxy.yml -i ${target_host}, -t install --private-key ${SSH_KEY} -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"'
}
} }
} }
} }
@@ -51,8 +61,13 @@ pipeline {
} }
steps { steps {
script { script {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: params.password]]]) { withCredentials([
sh 'ansible-playbook rproxy.yml -i ${target_host}, -t add_config -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'),
usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password')
]) {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) {
sh 'ansible-playbook rproxy.yml -i ${target_host}, -t add_config --private-key ${SSH_KEY} -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"'
}
} }
} }
} }