简体   繁体   English

检查日期是否匹配,然后在 groovy 中向 stringbuilder 发送 yes

[英]Check date if matching then send yes to stringbuilder in groovy

I am trying to send schedule for today's deployment so for that I am trying to comparing the dates and if date matches then it should "YES" to stringbuilder and if it doesn't match then it should send "No" to stringbuilder respectively.我正在尝试为今天的部署发送时间表,因此我正在尝试比较日期,如果日期匹配,那么它应该“是”给 stringbuilder,如果它不匹配,那么它应该分别向 stringbuilder 发送“否”。 For that I have written groovy script for Jenkins likewise-为此,同样为 Jenkins 编写了 groovy 脚本-

                    echo "FIT2 Deployment started"
                    if(runConfig.FIT2Deploy){
                        FIT2Deploy = sb.append(padToLength('FIT2', 15)).append('|')
                    }
            }
            stage('Log Intent') {
              echo runConfig.stringify()
            } 

           String makeMarkFor(boolean bool) {
              return (bool ? "Yes" : "No")
           }
           class RunConfig implements Serializable {

    String padToLength(String initialValue, int length) {
        String tmpVal = initialValue
        while (tmpVal.length() < length) {
            tmpVal = tmpVal + " "
        }
        return tmpVal
    }

    String centerPadToLength(String initialValue, int length) {
        String tmpVal = initialValue
        boolean atFront = false
        while (tmpVal.length() < length) {
            if (atFront) {
                tmpVal = " " + tmpVal
            } else {
                tmpVal = tmpVal + " "
            }
            atFront = !atFront
        }
    }

    String stringify() {
        def sb = StringBuilder.newInstance()
        sb.append('The following is the schedule for today ').append('|')
        sb.append('\n================================\n')
        sb.append(padToLength('Environment', 15)).append('|')
        sb.append(padToLength(' Deploy', 8))
        sb.append('\n--------------------------------\n')

        //sb.append(padToLength('FIT2', 15)).append('|')
        sb.append(centerPadToLength(makeMarkFor(FIT2Deploy), 8))
        sb.toString() 
        }
}

But It is not working can someone please help me?它不起作用有人可以帮助我吗? I am expecting output-我期待输出- 在此处输入图片说明

You can change padToLength('Environment', 15) to 'Environment'.padRight(15) and get rid of your padToLength method您可以将padToLength('Environment', 15)更改为'Environment'.padRight(15)并摆脱您的padToLength方法

You can change centerPadToLength(makeMarkFor(FIT2Deploy), 8) to makeMarkFor(FIT2Deploy).center(8) and get rid of your centerPadToLength method您可以将centerPadToLength(makeMarkFor(FIT2Deploy), 8)更改为makeMarkFor(FIT2Deploy).center(8)并摆脱您的centerPadToLength方法

And then looking at your code, you probably want makeMarkFor(runConfig.FIT2Deploy).center(8) , but it's hard to tell as the logic is a bit complex with the same variable names used in different context然后查看您的代码,您可能需要makeMarkFor(runConfig.FIT2Deploy).center(8) ,但很难说,因为逻辑有点复杂,在不同的上下文中使用相同的变量名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM