代码之家  ›  专栏  ›  技术社区  ›  Ashar

Jenkins管道脚本错误:管道java结束。lang.NoSuchMethodError:未找到此类DSL方法“httpRequest”

  •  0
  • Ashar  · 技术社区  · 5 年前

    我想了解詹金斯另一份工作的最新情况 Backup_Precheck 在我当前的管道脚本中。

    下面是我的管道脚本。

    import groovy.json.JsonSlurper
    
    pipeline 
    {
       agent any
       stages {
    
          stage('check Job Backup_Precheck status'){
    
             steps {
      
                script{
     
                  if(checkStatus() == "RUNNING" ){
                      timeout(time: 60, unit: 'MINUTES') {
                           waitUntil {
    
                             def status = checkStatus()
                                return  (status == "SUCCESS" || status == "FAILURE" || status == "UNSTABLE" || status == "ABORTED")
                      }
                }
            }
    
            if( checkStatus() != "SUCCESS" ){
               error('Stopping Job Weekend_Backup becuase job Backup_Precheck is not successful.')
            } else {
          
                echo 'Triggering ansible backup automation'
                          
          } // script end
                         
         } //steps ends here
        
    } // stage ends here
       
    
    stage('Hello') {
            
        steps {  echo 'Hello World'}
        
       }
        
      } //step closes
        
    }    
        
    def checkStatus() {
            
    def statusUrl = httpRequest "https://portal.myshop.com:9043/job/Backup_Precheck/lastBuild/api/json"
        
    def statusJson = new JsonSlurper().parseText(statusUrl.getContent())
            
                        return statusJson['result']
        
        }
    

    [Pipeline]{(Hello)阶段“Hello”已跳过,原因是以前的失败 [Pipeline]}[Pipeline]//阶段[Pipeline]}[Pipeline]//节点 [Pipeline]管道java的末尾。lang.NoSuchMethodError:没有这样的DSL 在步骤[ansiColor,ansiblePlaybook, ansibleTower、ansibleTowerProjectRevision、ansibleTowerProjectSync、, ansibleVault、存档、bat、生成、捕获错误、签出、删除目录、, 目录、dockerFingerprintFrom、dockerFingerprintRun、dockerNode、echo、, 库资源、加载、锁定、邮件、里程碑、节点、并行、, powershell、属性、publishHTML、pwd、pwsh、readFile、readTrusted、, ValidateClarativeEpiLine、Waitill、warnError、withContext、, 使用凭据,使用DockerConteta

    我明白,我可能需要我安装HTTP请求插件,以解决上述问题。

    HTTP Request Plugin ? 如果是这样,请引导我。

    0 回复  |  直到 5 年前
        1
  •  2
  •   smelm    5 年前

    有一种更简单的方法可以做到这一点。由于Jenkins是用Java实现的,管道在Groovy(同一个VM)中运行,因此您可以从Jenkins代码访问每个类和函数。为了获得作业当前生成的生成结果,可以执行以下操作:

    def job = jenkins.model.Jenkins.instance.getItemByFullName("<folder>/<job name>")
    def result = job.getLastBuild().result
    

    这种方法非常强大,可以在管道运行时对Jenkins进行大量控制。

    要了解更多信息,您可以:

    [2]: https://bateru.com/news/2011/11/code-of-the-day-groovy-print-all-methods-of-an-object/ . 你可以从那里继续前进。