Files
rproxy/Jenkinsfile

96 lines
3.7 KiB
Plaintext
Raw Normal View History

2024-06-23 01:05:03 +03:00
pipeline {
agent any
2024-09-29 01:48:21 +03:00
options {
buildDiscarder logRotator (
numToKeepStr: '5',
daysToKeepStr: '7',
artifactNumToKeepStr: '10',
artifactDaysToKeepStr: '7'
)
2025-06-08 01:38:44 +03:00
ansiColor('xterm')
timestamps()
2024-09-29 01:48:21 +03:00
}
2026-01-17 19:05:14 +03:00
environment {
INFRA_CONFIG_REPO = credentials("INFRA_CONFIG_REPO")
}
2024-06-23 01:05:03 +03:00
parameters {
2026-01-17 19:05:14 +03:00
choice(name: "infra", choices: ['prod', 'dev'], description: "Select infrastructure type")
choice(name: "repo_location", choices: ['local', 'remote'], description: "Select repository location")
string(name: "target_host", defaultValue: "", trim: true, description: "Target host for rproxy installation")
2025-07-20 18:04:47 +03:00
booleanParam(name: 'update_job', defaultValue: false, description: 'Update job, free run, no changes')
2024-06-23 01:05:03 +03:00
}
stages {
2025-07-20 18:04:47 +03:00
stage('Update Job') {
when {
expression {
return params.update_job
}
}
steps {
script {
currentBuild.getRawBuild().getExecutor().interrupt(Result.SUCCESS)
sleep(1)
}
}
}
2025-06-08 01:38:44 +03:00
stage('Prepare inventory') {
steps {
script {
def hostsFile = new File("${WORKSPACE}/hosts.ini")
hostsFile.append('[all]')
hostsFile.append('\n' + params.target_host)
println hostsFile.getText('UTF-8')
}
}
}
2026-01-17 19:05:14 +03:00
stage('Get environment') {
steps {
script {
dir('infra-config') {
git url: env.INFRA_CONFIG_REPO,
branch: params.infra,
credentialsId: 'JENKINS_GIT_ACCESS'
sh "ansible-playbook render.yml"
infraVars = readYaml file: "./global.yml"
}
}
}
}
2024-06-30 18:30:49 +03:00
stage('Install Rproxy') {
steps {
script {
2026-01-17 19:05:14 +03:00
images_repo_url = infraVars["${params.repo_location}"]["repos"]["registry_url"]
2024-09-29 01:48:21 +03:00
withCredentials([
sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'),
usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password')
]) {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) {
2025-06-08 01:38:44 +03:00
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "xterm"]) {
ansiblePlaybook(
playbook: 'rproxy.yml',
inventory: 'hosts.ini',
colorized: true,
2026-01-17 19:05:14 +03:00
extras: "--private-key ${SSH_KEY}",
extraVars: [
ansible_user: [value: "${username}", hidden: false],
ansible_password: [value: "${password}", hidden: true],
image_repo: [value: "${images_repo_url}", hidden: false]
]
2025-06-08 01:38:44 +03:00
)
}
2024-09-29 01:48:21 +03:00
}
2024-06-30 18:30:49 +03:00
}
}
}
}
2024-06-23 01:05:03 +03:00
}
2025-06-08 01:38:44 +03:00
post {
always {
cleanWs(patterns: [
[pattern: 'hosts.ini', type: 'INCLUDE']
])
}
}
2024-06-23 01:05:03 +03:00
}