jenkinsgroovyjenkins-pipelinejenkins-groovygroovyscriptengine

Jenkins file groovy issues


Hi My jenkins file code is as follows : I am basically trying to make call to a python script and execute it, I have defined some variables in my code : And when i am trying to run it, It gives no such property error in the beginning and I cant find out the reason behind it. I would really appreciate any suggestions on this .

import groovy.json.*

pipeline {
    agent {
        label 'test'
    }
    
    parameters {
        choice(choices: '''\
env1
env2'''
, description: 'Environment to deploy', name: 'vpc-stack')

        choice(choices: '''\
node1 
node2'''
, description: '(choose )', name: 'stack')

    }

    stages {

        stage('Tooling') {
            steps {

                script {

                    //set up terraform
                    def tfHome = tool name: 'Terraform 0.12.24'
                    env.PATH = "${tfHome}:${env.PATH}"
                    env.TFHOME = "${tfHome}"

                    

                }
            }
        }

        stage('Build all modules') {

            steps {
                    wrap([$class: 'BuildUser']) {

                        // build all modules
                        script {
                            if (params.refresh) {
                                echo "Jenkins refresh!"
                                currentBuild.result = 'ABORTED'
                                error('Jenkinsfile refresh! Aborting any real runs!')
                            }

                            sh(script: """pwd""")
                            
                            def status_code = sh(script: """PYTHONUNBUFFERED=1 python3 scripts/test/test_script.py /$vpc-stack""", returnStatus: true)

                            if (status_code == 0) {
                                currentBuild.result = 'SUCCESS'
                            }
                            if (status_code == 1) {
                                currentBuild.result = 'FAILURE' 
                            }
                        }
                    }
            }
        }
    }
    post {
        always {
            echo 'cleaning workspace'
            step([$class: 'WsCleanup'])
        }
    }
}

And this code is giving me the following error :

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

Any suggestions what can be done to resolve this.


Solution

  • Use another name for the choice variable without the dash sign -, e.g. vpc_stack or vpcstack and replace the variable name in python call.