异常错误:无此属性:课堂阶段:groovy.lang

hxzsmxv2  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(169)

我试图创建一个声明性的jenkins管道来部署aws lmabda,但每次都遇到这个错误:

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

我非常确定管道的语法,我发现它挂在“stage”表达式上非常奇怪,因为它是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"'
                    }
                }     
            }
        }

    }
}

知道输油管出了什么问题吗?

l7mqbcuq

l7mqbcuq1#

请检查您是否已安装所需的插件,如- workflow stage view等。

相关问题