【问题标题】:Jenkins Using checkout scm to clone repo from GithubJenkins 使用 checkout scm 从 Github 克隆 repo
【发布时间】:2020-11-24 05:02:15
【问题描述】:

概述:

  • 我正在尝试检查我的多配置 jenkins 管道中的 github 代码:

    package checkout
    void call() {
        println "checkout stage ..."
        node {
            deleteDir()
            checkout scm
        }
    }
    
  • 我正在使用 JTE(Jenkins 模板引擎)

问题:

但是 jenkins 在构建管道后抱怨错误Step checkout from the library checkout does not have the method call(GitSCM)。请在下面找到堆栈跟踪:

hudson.remoting.ProxyException: org.boozallen.plugins.jte.binding.TemplateException: Step checkout from the library checkout does not have the method call(GitSCM)
    at org.boozallen.plugins.jte.binding.injectors.StepWrapper.invoke(script1596520065305271654461.groovy:98)
    at org.boozallen.plugins.jte.binding.injectors.StepWrapper.call(script1596520065305271654461.groovy:60)
    at checkout.script15965200672531305703678.call(script15965200672531305703678.groovy:19)
    at ___cps.transform___(Native Method)
    at sun.reflect.GeneratedConstructorAccessor515.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.constructorCall(DefaultInvoker.java:25)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:97)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.GeneratedMethodAccessor632.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:107)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.GeneratedMethodAccessor632.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:89)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.GeneratedMethodAccessor632.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)

由于我是 groovy 和 Jenkins 的新手,如果您能分享任何真正的解决方案或想法,我将不胜感激。

【问题讨论】:

    标签: git groovy jenkins-pipeline checkout jenkins-template-engine


    【解决方案1】:

    我发现了我的问题并将其发布在此处以供像我这样的新手使用:

    我需要进行以下更改并重新运行 jenkins 构建以解决问题:

    1. node关键字移动到/templates/jenkinsfile中的模板jenkinsfile

      node('<executer node>') {
       scm_checkout()
      }
      
    2. 更新/templates/directory 中的 pipeline_config.groovy 文件:

      libraries {
        merge = true
        scm_checkout
      }
      
    3. 将库目录名称更新为 scm_checkout。目录和文件名应该与 checkout 不同,以避免将checkout(scm) 引用到错误的库。

    4. 结帐库应该在libraries/scm_checkout/scm_checkout.groovy,内容如下:

      void call() {
          println "checkout stage ..."
      
          deleteDir()
      
          def checkout = checkout(scm)
      
      
      } 
      

    【讨论】:

      猜你喜欢
      • 2021-07-16
      • 1970-01-01
      • 2012-08-25
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      相关资源
      最近更新 更多