首页 > 解决方案 > hudson.remoting.ProxyException:groovy.lang.MissingPropertyException:没有这样的属性:任何类:

问题描述

我有 jenkins 声明式管道,我也用声明式管道加载 sub_mudule 。

#!groovy

def jenkins_ci_examples = [String:Object]
def secrets_vault = "secrets_vault.groovy"
def vars=[String:Object];

pipeline {
    agent any

    stages{
        stage("Begin"){
            steps {
                script {
                    stage("Checkout"){
                        deleteDir()
                        checkout scm
                        sh "git submodule foreach --recursive git pull origin master"
                    }
                    stage("import common_vars") {
                        vars = load "jenkins-ci-examples/vars/common_vars.groovy"
                        jenkins_ci_examples.common_vars = vars.UpdateVars();
                    }
                    stage("merge common and project_vars"){
                        vars = load "vars/project_vars.groovy"
                        jenkins_ci_examples.project_vars = vars.UpdateVars("ssh://git@git.com:8080/some/repo.git", "master")
                        jenkins_ci_examples.vars = jenkins_ci_examples.common_vars.GetVars()+ jenkins_ci_examples.project_vars.GetVars()
                    }
                    stage("import template ${secrets_vault}") {
                        println("${env.STAGE_NAME}")
                        currentBuild.displayName = "import template ${secrets_vault}"
                        currentBuild.description = "import template ${secrets_vault}"
                        sh "ls -las; cd jenkins-ci-examples; ls -las";
                        jenkins_ci_examples.sub_module = load "jenkins-ci-examples/${secrets_vault}"
                    }
                    stage("run template ${secrets_vault}") {
                        println("${env.STAGE_NAME}")
                        sh "ls -las; cd jenkins-ci-examples; ls -las";
              jenkins_ci_examples.sub_module.ansible_secrets(jenkins_ci_examples.vars);
                    }
                }
            }
        }

    }


}
 

上下文加载 secrets_vault.groovy

def ansibledevops_secrets(HashMap <String,Object> vars)
{
    def template1 ="spread_sshkeys"
    pipeline {
        agent any

        stages {
            stage('Dynamic Stages') {

                steps {
                    script {
                        stage("import template ${template1}"){
                            println("${env.STAGE_NAME}")
                        }
                        stage("run template ${template1}"){
                            println("${env.STAGE_NAME}")
                        }
                    }
                }
            }

        }
    }


}

return this

尝试运行返回错误

hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class: Script3

但是如果使用脚本管道

node {
                    stage("Checkout") {
                        deleteDir()
                        checkout scm
                        sh "git submodule foreach --recursive git pull origin master"
                        print "Result " + vars;
                    }
}

没有错误。

帮助解决声明式管道变体的问题。

标签: jenkinsjenkins-groovyjenkins-declarative-pipelinejenkins-scriptler

解决方案


推荐阅读