pipeline {
    agent {
      label "og1"
    }
    parameters {
        choice(name: 'ENVIRONMENT', choices: ['prepro', 'dev', 'prod'], description: 'Environment where to run the tests, by default prepro')
    }
    environment {
        def currentDayOfWeek = new Date().format('EEEE')
        //def branchName = env.BRANCH_NAME
    }

    stages {
        stage('Start') {
            steps {
                echo 'Jenkinsfile for opengnsys'
            }
        }
        stage('Borrar Snapshot') {
            steps {
                vSphere buildStep: [$class: 'DeleteSnapshot', consolidate: false, failOnNoExist: false, snapshotName: "og1-jenkins-test-${currentDayOfWeek}", vm: 'og1'], serverName: 'Esxi Jenkins UMA Cloud'
            }
        }

        stage('Crear Snapshot') {
            steps {
                vSphere buildStep: [$class: 'TakeSnapshot', description: 'og1-jenkins-test', includeMemory: false, snapshotName: "og1-jenkins-test-${currentDayOfWeek}", vm: 'og1'], serverName: 'Esxi Jenkins UMA Cloud'
            }
        }

        stage('Create temporaly directory') {
            when {
                expression {
                boolean fileNotPresent = !fileExists("/var/tmp/opengnsys")
                return fileNotPresent
                }
            }

            steps {
            sh "mkdir /var/tmp/opengnsys"
            }
        }

        stage('Copy to temporaly directory') {
            steps {
                sh "cp -r ./* /var/tmp/opengnsys"
                sh 'ls -la /var/tmp/'
                sh "ls -la /var/tmp/opengnsys"
            }
        }
 //       stage('Execute opengnsys update') {
 //          steps {
  //              dir("/var/tmp/opengnsys/installer"){
 //                   sh 'pwd'
 //                   sh 'sudo ./opengnsys_update.sh'
//
   //             }
   //         }
  //      }
    }
}
