The CloudBees Amazon AWS CLI plugin provisions the AWS CLI in your jobs so that you can deploy applications or interact with an Amazon Web Services environment.
The AWS CLI only supports Linux distributions. |
AWS CLI Pipeline syntax
The Groovy syntax looks like:
node { // ... withAwsCli( (1) credentialsId: 'aws-cleclerc-beanstalk', (2) defaultRegion: 'us-east-1']) { (3) sh ''' (4) # COPY CREATED WAR FILE TO AWS S3 aws s3 cp target/petclinic.war s3://cloudbees-aws-demo/petclinic.war # CREATE A NEW BEANSTALK APPLICATION VERSION BASED ON THE WAR FILE LOCATED ON S3 aws elasticbeanstalk create-application-version \ --application-name petclinic \ --version-label "jenkins$BUILD_DISPLAY_NAME" \ --description "Created by $BUILD_TAG" \ --source-bundle=S3Bucket=cloudbees-aws-demo,S3Key=petclinic.war # UPDATE THE BEANSTALK ENVIRONMENT TO CREATE THE NEW APPLICATION VERSION aws elasticbeanstalk update-environment \ --environment-name=petclinic-qa-env \ --version-label "jenkins$BUILD_DISPLAY_NAME" ''' } }
1 | withAwsCli step |
2 | ID of the IAM credentials to configure the AWS CLI |
3 | Default AWS region |
4 | aws commands used in sh steps, the AWS CLI is configured with the desired credentials and AWS region. |
Evaluating aws
commands result
Evaluating the result of the aws
command is key to the logic of your Pipeline.
-
aws
commands return non zero exit code in case of error and thus, shell steps will by default fail if aaws
command fails -
The AWS CLI plugin by default uses the JSON output format for
aws
commands. This output format can be overridden using theAWS_DEFAULT_OUTPUT
environment variable. Acceptable values are JSON (json
), tab-delimited text (text
) and ASCII-formatted table (table
). For more details, see Controlling Command Output from the AWS Command Line Interface from the AWS documentation. -
To capture the output (stdout and stderr) of an
aws
command in a Pipeline, please refer to the tips provided in the Request For Enhancements -
JENKINS-28302: Pipeline steps should expose console output to script somehow
Pipeline snippet generator
You can generate the Pipeline statement to setup the AWS CLI using the Jenkins Pipeline Snippet Generator.
Configuring a job
To enable the Amazon Web Services CLI in a job:
-
Navigate to the Configuration page of the job and, in the Build Environment section, check Setup Amazon Web Services CLI.
You can then select:
-
API Credentials: Amazon Web Services Access Key to use when invoking the Amazon Web Services CLI (cf
aws configure
). -
Default Region: The Amazon Web Services Default Region (cf
aws configure
).