Issue
I want to perform sum of integers (c = a+b) in jenkins, initially i have defined the value of a by giving def a = 5, but I want to take values of b from parameters . So i added string parameter but this is not considering as integer ,instead it is just attaching the 2 values , is there any way so that i can take inputs of b from parameter and perform addition the pipeline is as follows
pipeline { agent any stages { stage('Stage 1') { steps { script{
def a = 5;
//def b = "${params.inputvalue}";
c = "${a + b}" ;
echo "value of c is ${c}"
}
}
}
}
}
in parameter if i give value of b as 2 the output it's giving as 25 but the expected output is 7 i.e 2+5
Solution
I could solve this by converting string parameter to integer
int a = 10;
stage('arithmetic stage') {
int b = params.Value;
c = a + b;
echo "${c}"
}
here "Value" is String parameter name .
Answered By - Kalyan Raparthi
Answer Checked By - Robin (JavaFixing Admin)