0

I am trying to perform a string comparison which has 2 string values that should be equal (see consumer_var.equals('ED UI')). However, they are not recognised as equal (They should both be 'ED UI') and the "else" block is running when it shouldn't be.

 def consumer_var = env.consumer                        
 println "consumer param is " + consumer_var          
 println "are " + consumer_var + " and 'ED UI' equal? " + consumer_var.equals('ED UI')
          
if(consumer_var.equals('ED UI'))
{
        println "hey, consumer ${consumer} is ED UI!"
        
}
else 
{
    println "consumer is ${consumer}"
}    
                          

The result is:

[Pipeline] echo

consumer param is Ed UI

[Pipeline] echo

are Ed UI and 'ED UI' equal? false

[Pipeline] echo

consumer is Ed UI


If somebody can create an if statement to check whether the build parameter called "consumer" is equal to a string 'ED UI', that would be great.

ycr
  • 12,828
  • 2
  • 25
  • 45
Alexb1999
  • 79
  • 2
  • 10
  • 2
    "_are Ed UI and 'ED UI' equal?_" these are not equal, the first has a lower case `d`. If you want to compare them, and you're not worried about non English characters, just compare `consumer_var.toUpperCase()` – tim_yates Nov 26 '22 at 00:33
  • @tim_yates, `str2.equalsIgnoreCase( str )` – Ian W Nov 26 '22 at 09:59
  • Oh god, it was just the difference between "d" and "D" as you said.. thanks so much! – Alexb1999 Nov 26 '22 at 14:12

0 Answers0