imagescanningaws-ecrjenkins-pipeline-unit

To run aws ECR scan commands in jenkinsfile


Trying to run below 2 commands in Jenkins file NOTE: below commands are working fine locally where Jenkins is installed

sh '''  aws ecr start-image-scan --registry-id 123 \
           --repository-name test1 \
           --image-id imageTag=${BUILD_NUMBER} --output json | tee ecr_start_scan_${BUILD_NUMBER}.txt'''


sh ''' aws ecr describe-image-scan-findings --registry-id 123 \
          --repository-name test \
          --image-id imageTag=${BUILD_NUMBER}  --output json | tee ecr_scanResult_${BUILD_NUMBER}.txt'''

Below is the output for both the commands:

+ aws ecr start-image-scan --repository-name valhalla --image-id imageTag=13 --region ap-southeast-1 --output json
+ tee ecr_start_scan_13.txt
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: argument operation: Invalid choice, valid choices are:

batch-check-layer-availability           | batch-delete-image                      
batch-get-image                          | complete-layer-upload                   
create-repository                        | delete-lifecycle-policy                 
delete-repository                        | delete-repository-policy                
describe-images                          | describe-repositories                   
get-authorization-token                  | get-download-url-for-layer              
get-lifecycle-policy                     | get-lifecycle-policy-preview            
get-repository-policy                    | initiate-layer-upload                   
list-images                              | put-image                               
put-lifecycle-policy                     | set-repository-policy                   
start-lifecycle-policy-preview           | upload-layer-part                       
get-login                                | help                                    

Solution

  • Update AWS CLI version. I had the same issue with aws-cli/1.11.13. But got the expected result in aws-cli/1.18.16