Home > OS >  If condition is not getting executed in my Jenkinsfile
If condition is not getting executed in my Jenkinsfile

Time:01-10

properties([parameters([choice(choices: ['c ', 'a', 'd'], name: 'Run_For', description: 'Selecet \'c\' for clone and upload the  cloned repos to S3 \n Slecet \'a\' for archive the repos . \n Select \'d\' for the deletion of the Repos')])])
gagan = params.Run_For
node {
    stage('Example') {
        choice = "c"
        echo Run_For

        println Run_for.getClass() // its string only 
        // someObject.getClass()
        if (Run_For.equals('c')) {
            println(" into the if ") // if is not accessiable i am not sure why 
            echo " yaya "
        }
        if (choice == "c") {
            println(" into the 2nd if ") //  this is accessible 
            echo " yaya 2 "
        }
    }
}

I am not sure what I am missing. I need to figure out why my first if block is not accessible.

CodePudding user response:

Try the following condition.

if (params.Run_For.trim().equals("c")) {
    println(" into the if ") // if is not accessiable i am not sure why 
    echo " yaya "
}
  • Related