UnsupportedOperationException:必须使用接口java.util.List

时间:2018-10-17 20:41:47

标签: jenkins groovy

运行Jenkinsfile测试,下一阶段返回UnsupportedOperationException: must specify $class with an implementation of interface java.util.List

stage('Checkout') {
    steps {
        checkout([$class: 'GitSCM', 
            branches: [name: '*/master'], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'CleanBeforeCheckout'], 
                [$class: 'RelativeTargetDirectory', relativeTargetDir: 'targetDir']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[credentialsId: 'jenkinsserviceaccount',
                url: 'https://bitbucket.company.net/scm/moak/myTestRepo.git']]])
    }
}

我确实更改了一些名称,以便在此处发布,但是上面的内容是使用Jenkins代码段生成器创建的。对结帐可能出什么问题有任何想法吗?

在Jenkins控制台中,我看到的例外更多。

java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List
    at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:503)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:341)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:282)
Caused: java.lang.IllegalArgumentException: Could not instantiate 
    {extensions=[{$class=CleanBeforeCheckout}, {$class=RelativeTargetDirectory, relativeTargetDir=stateStore}], 
    submoduleCfg=[], 
    userRemoteConfigs=[{credentialsId=jenkinsserviceaccount, url=https://bitbucket.hylandqa.net/scm/moak/hyland-statestore.git}], 
    doGenerateSubmoduleConfigurations=false, 
    branches={name=*/master}} 
for GitSCM(userRemoteConfigs: UserRemoteConfig(url: String, name: String, refspec: String, credentialsId: String)[], 
    branches: BranchSpec(name: String)[], 
    doGenerateSubmoduleConfigurations: boolean, 
    submoduleCfg: org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class hudson.plugins.git.SubmoduleConfig[], 
    browser: GitRepositoryBrowser{AssemblaWeb(repoUrl: String) | BitbucketWeb(repoUrl: String) | CGit(repoUrl: String) | FisheyeGitRepositoryBrowser(repoUrl: String) | 
        GitBlitRepositoryBrowser(repoUrl: String, projectName: String) | GitLab(repoUrl: String, version: String) | GitList(repoUrl: String) | GitWeb(repoUrl: String) | 
        GithubWeb(repoUrl: String) | Gitiles(repoUrl: String) | GitoriousWeb(repoUrl: String) | GogsGit(repoUrl: String) | KilnGit(repoUrl: String) | 
        Phabricator(repoUrl: String, repo: String) | RedmineWeb(repoUrl: String) | RhodeCode(repoUrl: String) | Stash(repoUrl: String) | 
        TFS2013GitRepositoryBrowser(repoUrl: String) | ViewGitWeb(repoUrl: String, projectName: String)}, 
        gitTool: String, extensions: GitSCMExtension{AuthorInChangelog() | 
        BuildChooserSetting(buildChooser: BuildChooser{AncestryBuildChooser(maximumAgeInDays: int, ancestorCommitSha1: String) | 
        DefaultBuildChooser() | InverseBuildChooser()}) | ChangelogToBranch(options: ChangelogToBranchOptions(compareRemote: String, compareTarget: String)) | 
        CheckoutOption(timeout: int) | CleanBeforeCheckout() | CleanCheckout() | 
        CloneOption(shallow: boolean, noTags: boolean, reference: String, timeout: int, depth?: int, honorRefspec?: boolean) | 
        DisableRemotePoll() | GitLFSPull() | IgnoreNotifyCommit() | LocalBranch(localBranch: String) | MessageExclusion(excludedMessage: String) | 
        PathRestriction(includedRegions: String, excludedRegions: String) | PerBuildTag() | 
        PreBuildMerge(options: UserMergeOptions(mergeTarget: String, fastForwardMode?: GitPluginFastForwardMode[FF, FF_ONLY, NO_FF], mergeRemote?: String, mergeStrategy?: Strategy[DEFAULT, RESOLVE, RECURSIVE, OCTOPUS, OURS, SUBTREE, RECURSIVE_THEIRS])) | 
        PruneStaleBranch() | RelativeTargetDirectory(relativeTargetDir: String) | ScmName(name: String) | 
        SparseCheckoutPaths(sparseCheckoutPaths: SparseCheckoutPath(path: String)[]) | 
        SubmoduleOption(disableSubmodules: boolean, recursiveSubmodules: boolean, trackingSubmodules: boolean, reference: String, timeout: int, parentCredentials: boolean) | 
        UserExclusion(excludedUsers: String) | UserIdentity(name: String, email: String) | WipeWorkspace()}[])

1 个答案:

答案 0 :(得分:1)

您看到此错误,因为branches键需要保留嵌套在列表中的地图。所以应该是:

branches: [[name: '*/master']]

代替

branches: [name: '*/master']
  

来源:https://jenkins.io/doc/pipeline/steps/workflow-scm-step/#code-checkout-code-general-scm

整个阶段如下:

stage('Checkout') {
    steps {
        checkout([$class: 'GitSCM', 
            branches: [[name: '*/master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'CleanBeforeCheckout'], 
                [$class: 'RelativeTargetDirectory', relativeTargetDir: 'targetDir']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[credentialsId: 'jenkinsserviceaccount',
                url: 'https://bitbucket.company.net/scm/moak/myTestRepo.git']]])
    }
}

关于您看到的错误-工作流插件使用Groovy的功能将Map转换为另一种类型。如果所有映射键正确地映射到一个类字段,例如他们必须存储相同的类型。当branches存储Map而不是List<Map>时,整个映射无法转换为表示SCM配置的对象。