Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 1 | node('sre-team-infra') { |
| 2 | timestamps() { |
| 3 | ansiColor('xterm') { |
| 4 | tmp_jenkins_config = '/dev/shm/sre-jenkins-job-builder.ini' |
| 5 | stage('Checkout') { |
| 6 | checkout scm |
| 7 | } |
| 8 | stage('Prepre venv'){ |
| 9 | sh """ |
| 10 | if [ ! -d .venv ]; then |
Hanna Arhipova | 4759ae4 | 2021-01-11 12:48:14 +0200 | [diff] [blame] | 11 | echo "Can't find python virtual env, installing" |
Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 12 | virtualenv -p python3 .venv |
| 13 | fi |
| 14 | if [ -z "\$(./.venv/bin/pip freeze | grep jenkins-job-builder)" ]; then |
dtsapikov | c7fa32a | 2023-04-12 19:40:03 +0400 | [diff] [blame] | 15 | ./.venv/bin/pip install 'jenkins-job-builder>=2.0.0.0b2' dataclasses |
Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 16 | fi |
| 17 | """ |
| 18 | } |
| 19 | stage('Prepre config'){ |
| 20 | withCredentials([usernamePassword(credentialsId: 'jenkins-job-builder', |
| 21 | passwordVariable: 'jpass', usernameVariable: 'juser')]) { |
| 22 | sh """ |
| 23 | cp jobs/config/sre-jenkins-job-builder-example.ini ${tmp_jenkins_config} |
| 24 | sed -i "s/user=some_user/user=\${juser}/g" ${tmp_jenkins_config} |
| 25 | sed -i "s/password=some_password/password=\${jpass}/g" ${tmp_jenkins_config} |
| 26 | """ |
| 27 | } |
| 28 | } |
| 29 | stage('Deploy jobs'){ |
Pavel Glazov | 6340740 | 2022-09-19 16:12:13 +0400 | [diff] [blame] | 30 | sh """ |
| 31 | cd jobs |
| 32 | ../.venv/bin/jenkins-jobs --conf ${tmp_jenkins_config} test ./ |
| 33 | """ |
| 34 | if ("${env.DRY_RUN}" != "true") { |
Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 35 | sh """ |
| 36 | cd jobs |
| 37 | ../.venv/bin/jenkins-jobs --conf ${tmp_jenkins_config} update ./ |
Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 38 | """ |
Pavel Glazov | 6340740 | 2022-09-19 16:12:13 +0400 | [diff] [blame] | 39 | } |
| 40 | sh """rm ${tmp_jenkins_config}""" |
Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |