2

I have jenkins Declarative pipeline, where I load sub_mudule with Declarative pipeline too.

#!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);
                    }
                }
            }
        }

    }


}
 

context load 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

Try run returned error

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

But if use scripted pipeline

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

errors absent.

Help to solve problem with Declarative pipeline variant.

Nikolay Baranenko
  • 1,582
  • 6
  • 35
  • 60

0 Answers0