Jenkins 声明性管道 groovy.lang.MissingPropertyException:没有此类属性:类的阶段:groovy.lang

问题描述 投票:0回答:1

我正在尝试创建一个声明式 Jenkins 管道来部署 AWS Lambda,但每次我都会遇到此错误:

groovy.lang.MissingPropertyException: No such property: stage for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at

我非常确定管道的语法,并且我发现它挂在“舞台”表达式上非常奇怪,因为它是 Groovy 语法的本机。

下面是管道:

pipeline {
    agent {
        label 'node1'
    }
    environment {
        awsRegion = 'some_region'
        // Role name is the same in ALL AWS accounts
        Role = 'some_role'
        awsAccount = 'Some_account_number'
        envName = 'some_env'
        paramsfile = 'vars.json'
        templatebody = 'PATH/lambda-template.yml'
    }
    stages {
        stage('Init') {
            steps {
                echo 'Init done'
            }
        }

        stage('BuildBackend parameter file') {
            steps {
                withAWS(credentials:'jenkins_user', region:"eu-west-1") {
                    withAWS(role:"$cfnexecutionRole", roleAccount: targetAWSAccounts['targetaccount'], duration:900, roleSessionName:'jenkins-session') {
                        script{
                            for (def key in backendParamList.keySet()){
                                echo "Fetching ${key}"
                                backendParamValues[key] = sh(script:"aws ssm get-parameter --query 'Parameter.Value' --name '/config/${stageToParamPrefix[stage]}/lambda/${key}'", returnStdout: true).trim()
                                echo ParamValues[key]
                            }
                        }
                    }
                    // Next roleAccount depends on the param stage
                    withAWS(role:"$Role", roleAccount: targetAWSAccounts[stageToAccount[env.stage]], duration:900, roleSessionName:'jenkins-session') {
                        script{
                            def backendParams = "{\n"
                            def nbParams = 0
                            for (def key in backendParamList.keySet()){
                                echo "Writing parameter ${key}"
                                if(nbParams > 0){
                                    backendParams += ","
                                }
                                backendParams += "{\"ParameterKey\":\"${backendParamList[key]}\", \"ParameterValue\": ${backendParamValues[key]}}"
                                backendParams += "\n"
                                nbParams += 1
                            }
                            backendParams += "}"
                            writeFile(file:'$paramsfile', text: backendParams)
                            echo backendParams
                            // deploy secrets
                            sh "aws "
                        }
                    }
                }
            }
        }

        stage('Check params file') {
            steps {
                sh "cat $paramsfile"
            }
        }

        stage('Deploy lambda using cloudformation template') {
            steps {
                withAWS(credentials:'user_credentials', region:"$awsRegion") {
                    echo "Assume Cloudformation-Execution-Role - AWS Account: $awsAccount"
                    withAWS(role:"$Role", roleAccount:"$awsAccount", duration:900, roleSessionName:'jenkins-session'){
                    sh'aws cloudformation create-stack --stack-name "$stackname" --template-body "$templatebody" --parameters "$paramsfile"'
                    }
                }
            }
        }
    }
}

管道可能出现什么问题?

jenkins groovy jenkins-pipeline cicd
1个回答
-1
投票

请检查您是否安装了所需的插件,例如 - 工作流程 舞台视图 等等

© www.soinside.com 2019 - 2024. All rights reserved.