Implement JJB, add backup script for jenkins

PROD-34544
Change-Id: Ie4d31934582169ae18cbaa56dd21c141ce49712b
diff --git a/jobs/pipelines/self-deploy-jobs.groovy b/jobs/pipelines/self-deploy-jobs.groovy
new file mode 100644
index 0000000..5815cd3
--- /dev/null
+++ b/jobs/pipelines/self-deploy-jobs.groovy
@@ -0,0 +1,38 @@
+node('sre-team-infra') {
+    timestamps() {
+        ansiColor('xterm') {
+            tmp_jenkins_config = '/dev/shm/sre-jenkins-job-builder.ini'
+            stage('Checkout') {
+                checkout scm
+            }
+            stage('Prepre venv'){
+                sh """
+                if [ ! -d .venv ]; then
+                  echo "Can't find python virtal env, installing"
+                  virtualenv -p python3 .venv
+                fi
+                if [ -z "\$(./.venv/bin/pip freeze | grep  jenkins-job-builder)" ]; then
+                   ./.venv/bin/pip install 'jenkins-job-builder>=2.0.0.0b2'
+                fi
+                """
+            }
+            stage('Prepre config'){
+                withCredentials([usernamePassword(credentialsId: 'jenkins-job-builder',
+                    passwordVariable: 'jpass', usernameVariable: 'juser')]) {
+                    sh """
+                    cp jobs/config/sre-jenkins-job-builder-example.ini ${tmp_jenkins_config}
+                    sed -i "s/user=some_user/user=\${juser}/g" ${tmp_jenkins_config}
+                    sed -i "s/password=some_password/password=\${jpass}/g" ${tmp_jenkins_config}
+                    """
+                }
+            }
+            stage('Deploy jobs'){
+                sh """
+                cd jobs
+                ../.venv/bin/jenkins-jobs --conf ${tmp_jenkins_config} update ./
+                rm ${tmp_jenkins_config}
+                """
+            }
+        }
+    }
+}
\ No newline at end of file