0

Jenkins 2.277.2 I am not that experienced with groovy and groovy operators but not sure whats wrong with the logic...

Getting this error:

Instance plan is dashDBStandard Cores are 4 and RAM is 16

...

hudson.AbortException: Invalid instance plan CPU value for TEST

'''
    print "Instance plan is ${db2instance_plan} Cores are ${cores} and RAM is ${ram}"
                            if ((db2instance_plan == 'dashDBStandard') && (cores > '16')) {
                               error "Invalid instance plan CPU value for TEST"
                            }
                            if ((db2instance_plan == 'dashDBStandard') && (ram > '64')) {
                               error "Invalid instance plan RAM value for TEST"
                            }
                            if ((db2instance_plan == 'dashDBNebula') && (cores < '4' )) {
                               error "Invalid instance plan CPU value for PROD"
                            }
                            if ((db2instance_plan == 'dashDBNebula') && (ram < '16' )) {
                               error "Invlaid instance plan RAM for PROD"
                            }

'''

1 Answers1

0

The error keyword in Jenkins pipelines just throws an hudson.AbortException with the specified message (stops the execution).

But it looks like you are treating cores and ram parameters as strings, and therefore the > operator will compare strings and not numbers as you probably intended.

If you input parameters are integers just use the following:

if ((db2instance_plan == 'dashDBStandard') && (cores > 16)) {

Otherwise if the input is a string you can convert it to a number:

if ((db2instance_plan == 'dashDBStandard') && (cores.toInteger() > 16)) {

See This Question for other ways to convert string to number

Noam Helmer
  • 5,310
  • 1
  • 9
  • 29