blob: 2d048bec4c4aa798204df808f9f82289e846684f [file] [log] [blame]
Sergey Galkin24ebd762020-01-14 14:36:34 +04001node('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 Arhipova4759ae42021-01-11 12:48:14 +020011 echo "Can't find python virtual env, installing"
Sergey Galkin24ebd762020-01-14 14:36:34 +040012 virtualenv -p python3 .venv
13 fi
14 if [ -z "\$(./.venv/bin/pip freeze | grep jenkins-job-builder)" ]; then
dtsapikovc7fa32a2023-04-12 19:40:03 +040015 ./.venv/bin/pip install 'jenkins-job-builder>=2.0.0.0b2' dataclasses
Sergey Galkin24ebd762020-01-14 14:36:34 +040016 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 Glazov63407402022-09-19 16:12:13 +040030 sh """
31 cd jobs
32 ../.venv/bin/jenkins-jobs --conf ${tmp_jenkins_config} test ./
33 """
34 if ("${env.DRY_RUN}" != "true") {
Sergey Galkin24ebd762020-01-14 14:36:34 +040035 sh """
36 cd jobs
37 ../.venv/bin/jenkins-jobs --conf ${tmp_jenkins_config} update ./
Sergey Galkin24ebd762020-01-14 14:36:34 +040038 """
Pavel Glazov63407402022-09-19 16:12:13 +040039 }
40 sh """rm ${tmp_jenkins_config}"""
Sergey Galkin24ebd762020-01-14 14:36:34 +040041 }
42 }
43 }
44}