首页 > 解决方案 > 无法在 Jenkins groovy 中进行减法运算

问题描述

我有一个构建管道。我还在学习 groovy。我正在做这样简单的事情

stage('test'){
def temp = 3 \\ reading this value from other env variable 
while(temp != 1) {
temp=temp-1
echo temp
}

}

它总是与 3 相呼应,而 while 是永无止境的。

标签: jenkinsgroovyjenkins-pipeline

解决方案


当您从环境变量中读取值时,您将其作为字符串获取

您需要将其转换为整数

def temp = env.SOMETHING.toInteger()

或者,将其定义为整数而不是使用def

int temp = env.SOMETHING

推荐阅读