相关文章推荐
爱笑的登山鞋  ·  Caused by: ...·  2 年前    · 
想发财的茴香  ·  python ...·  2 年前    · 

I’ve been working on a script for the past day but I keep encountering almost the same error. I’ve been trying multiple ways to cast from string to integer but Jenkins keeps complaining about it.

A snippet of code:

def value = "123456789 + abcdefghijklmnopqrstuvwxyz"
charCount = value.length()
build()
def build() {
    node {
        stage("Char Count") {
            echo "Length of the Output: ${charCount}"
            //int number = Integer.parseInt(charCount); (option #1)
           //for (int number = 1; i < charCount; i++)       (option #2)     
            if (number >= "16") {
                echo "Output too long"
            } else {
                echo "Can be added to Trello"

The idea is that value contains the output of a script executed in another stage (not included in above snippet).

  • First option: int number = Integer.parseInt(charCount);
    hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static java.lang.Integer.parseInt() is applicable for argument types: (java.lang.Integer) values: [39]
    
  • Second option: for (int number = 1; i < charCount; i++)
    Something similar to solution given in Cannot be cast to java.lang.Integer - #8 by Samuelcloud07
    java.lang.ClassCastException
    Finished: FAILURE
    

    Can someone please help me figure out a way were Jenkins doesn’t complain about Failed cast class java.lang.String to class java.lang.Integer?

    All I need is to be able to compare if charCount value is greater than a number, do something.

    Thanks in advance.

    echo "Length of the Output: ${charCount}" //int number = Integer.parseInt(charCount); (option #1) //for (int number = 1; i < charCount; i++) (option #2) if (number >= "16") { echo "Output too long" } else { echo "Can be added to Trello"

    How about:

    if (charCount > 16) {
       echo "too long"
    } else {
      echo "Not too long"
    
  •