javascript - 如何从 Jenkins 传入字符串并在 JavaScript 中转换为 Int
问题描述
一个 JS 新手 ~ 只是想将 Jenkins 的值传递到管道脚本中,然后将其转换为 Int。
管道片段
parameters {
string(name: 'TIMES_TO_LOOP', defaultValue: ['1'], description: 'Number of times to loop')
javascript 片段*
let timesToLoopThrough = 1; //set a default value
timesToLoopThrough = timesToLoopThrough.parseInt(agreementsToGenerate); //reset to value passed in
//use timesToLoopThrough in subsequent code
错误
TypeError: timesToLoopThrough.parseInt is not a function
解决方案
您想在类上调用 parseInt,而不是在实例上:
timesToLoopThrough = Number.parseInt(agreementsToGenerate);
或者干脆
timesToLoopThrough = parseInt(agreementsToGenerate);
如果 parseInt() 在全局范围内
推荐阅读
- android - 自定义图像视图切割左右边缘半圆形
- typescript - 在类验证器中验证具有异常数字可能性的数字
- java - 显示一个数字的另一个数字的幂 - 上标
- azure - Web App 出站响应不通过应用程序网关
- javascript - 从 Date() 转换为可读内容的 App 脚本
- java - 在 @RestControllerAdvise 上获取请求正文
- c - 如何修复两个警告“警告:格式指定类型'char *'但参数的类型为'char (*)[256]' [-Wformat]”
- python - 在双引号内调用变量
- scala - 在函数中获取类型不匹配错误作为scala中的参数
- mysql - JPA @OneToMany 与 mySql 和没有唯一键的第三个连接表