0

a JS novice ~ simply looking to pass in a value from Jenkins into a pipeline script that is then converted to an Int.

pipeline snippet

 parameters {
        string(name: 'TIMES_TO_LOOP', defaultValue: ['1'], description: 'Number of times to loop')

javascript snippet*

let timesToLoopThrough = 1; //set a default value

timesToLoopThrough = timesToLoopThrough.parseInt(agreementsToGenerate); //reset to value passed in

//use timesToLoopThrough in subsequent code

error

TypeError: timesToLoopThrough.parseInt is not a function
Steerpike
  • 1,712
  • 6
  • 38
  • 71
  • 1
    Does this answer your question? [Convert a string to an integer?](https://stackoverflow.com/questions/1133770/convert-a-string-to-an-integer) – Mickael B. Apr 29 '20 at 13:52

1 Answers1

0

You want to call parseInt on the class, not on the instance:

timesToLoopThrough = Number.parseInt(agreementsToGenerate);

or simply

timesToLoopThrough = parseInt(agreementsToGenerate);

if parseInt() is in global scope

Documentation here

Argee
  • 1,216
  • 1
  • 12
  • 22