V
V
VITYA-XY12021-02-09 01:50:39
Amazon Web Services
VITYA-XY1, 2021-02-09 01:50:39

How to create ami list in jenkins using extendedChoice parameter?

It works:

steps {
            script {   
        def images_ls_output = sh(script: "aws ec2 describe-images --query Images[*].[Name] --owner 111111111111 --region us-east-2 --output=text", returnStdout: true).trim()
        println "${images_ls_output}"
        def image = images_ls_output.tokenize().reverse()
        println "${image}"
            }
         }

It works:
parameters {
        extendedChoice(
            bindings: '',
            defaultValue: 'build',
            description: '',
            groovyClasspath: '',
            groovyScript: '''
            
                    def app_filter = "api.tar"
                    def s3_path = "s3://wpl-artifactory/"
                    def aws_s3_ls_output = "aws s3 ls ${s3_path} --region us-east-2".execute() | [\'sort\', \'-k 1\'].execute() | "grep ${app_filter}".execute() | [\'awk\', \'{ print $NF }\'].execute()
                    def files = aws_s3_ls_output.text.tokenize().reverse()
                    return files

            ''',
            multiSelectDelimiter: ',',
            name: 'BUILD_VERSION',
            quoteValue: false,
            saveJSONParameterToFile: false,
            type: 'PT_SINGLE_SELECT',
            visibleItemCount: 5
        )
}


This does not work:
parameters {
         extendedChoice(
            bindings: '',
            defaultValue: 'build',
            description: '',
            groovyClasspath: '',
            groovyScript: '''
                  
               def images_ls_output = sh(script: "aws ec2 describe-images --query Images[*].[Name] --owner 11111111 --region us-east-2 --output=text" returnStdout: true).trim()
               def image = images_ls_output.tokenize().reverse()
               return image

            ''',
            multiSelectDelimiter: ',',
            name: 'USE_EXISTING_IMAGE',
            quoteValue: false,
            saveJSONParameterToFile: false,
            type: 'PT_SINGLE_SELECT',
            visibleItemCount: 5
        )
}


What could be the reason?
"works" = in the first case, displays the values ​​of the array
"works" = in the second case, displays a list of images for selection in the parameter
"does not work" = in the third case, does NOT display a list of images for selection in the parameter

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question