发生异常:出现异常错误:无此属性:课程内容:groovy.lang.Binding

oxiaedzo  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(174)

我得到下面的错误Cloudbees Jenkins作业的控制台输出。错误:发生异常:出现异常错误:无此属性:课程内容:groovy.lang.Binding

Jenkins文件(特定阶段):

stage('Solution check') {

      when {
                 expression { params.SOLUTION_NAME_CHECK != 'None' }
            }
        steps {
            script{
            try{
            SOLUTION_NAME = "${params.SOLUTION_NAME_CHECK}"
            bat """
            call pac solution check --path C:\ManagedSolution.zip --outputDirectory C:\\SolutionCheck --geo Asia >> solutioncheck.log
           """
            powershell(returnStdout: true, script: """
                  $content = (Get-Content -Path '${WORKSPACE}\\${DATE_TIMESTAMPED_BN_DIR}\\${SOLUTION_NAME}\\solutioncheck.log.txt' -Tail 3).trim() | ConvertFrom-String -PropertyNames Critical,High,Medium,Low,Informational
                  $file = $content[1] -replace " ",""
                  $file | Foreach {
                  if(($_ -ilike "*critical=0*") -and ($_ -ilike "*High=0")){
                       echo "solution has no critical and High values"
                     }
                     else {
                       echo "Solution has critical and High values: $content[1]"
                     }
                }
                 """)
                 }
            catch (Exception err) {
                        echo 'Exception occurred: ' + err.toString()
             }

            }
        }
    }

请协助解决这个问题。谢谢

  • 埃曼特
neskvpey

neskvpey1#

尝试在所有非groovy变量的$之前添加一个转义符(\)。

\$content = (Get-Content -Path '${WORKSPACE}\\${DATE_TIMESTAMPED_BN_DIR}\\${SOLUTION_NAME}\\solutioncheck.log.txt' -Tail 3).trim() | ConvertFrom-String -PropertyNames Critical,High,Medium,Low,Informational
                  \$file = \$content[1] -replace " ",""
                  \$file | Foreach {
                  if((\$_ -ilike "*critical=0*") -and (\$_ -ilike "*High=0")){
                       echo "solution has no critical and High values"
                     }
                     else {
                       echo "Solution has critical and High values: \$content[1]"
                     }
                }

相关问题