diff --git a/Jenkinsfile b/Jenkinsfile index b6475d4..c1daf6c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,9 +10,13 @@ pipeline { ansiColor('xterm') timestamps() } + environment { + INFRA_CONFIG_REPO = credentials("INFRA_CONFIG_REPO") + } parameters { + 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") - string(name: "images_repo_url", defaultValue: "", trim: true, description: "Repository host with podman images (ex. rproxy.olsson.ul:5000)") booleanParam(name: 'update_job', defaultValue: false, description: 'Update job, free run, no changes') } stages { @@ -39,9 +43,25 @@ pipeline { } } } + 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" + } + } + } + } stage('Install Rproxy') { steps { script { + images_repo_url = infraVars["${params.repo_location}"]["repos"]["registry_url"] + withCredentials([ sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'), usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password') @@ -52,10 +72,12 @@ pipeline { playbook: 'rproxy.yml', inventory: 'hosts.ini', colorized: true, - extras: '''--private-key ${SSH_KEY} - -e "ansible_user=${username} - ansible_password=${password} - image_repo=${images_repo_url}"''' + 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] + ] ) } }