AWS CLI plugin

2 minute read

The CloudBees Amazon AWS CLI Plugin 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.

Using the AWS CLI in a Pipeline job

You can use it in any Pipeline job as a build wrapper.

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.

Pipeline snippet generator

You can generate the Pipeline statement to setup the AWS CLI using the Jenkins Pipeline Snippet Generator.

aws cli workflow snippet
Figure 1. AWS CLI Pipeline snippet

Configuring a job

To enable the Amazon Web Services CLI in a job:

  1. 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).

Using the AWS CLI in a job

Once you set up Amazon Web Services CLI in a job, you can use it in any Execute Shell or Execute Windows Batch Command step.

aws cli sample shell step
Figure 2. AWS CLI sample shell step

Watching and learning

Learn more on the integration of the AWS CLI in CloudBees Jenkins Platform with our screencasts.

Continuous Delivery with CloudBees Jenkins Platform and AWS Elastic Beanstalk
Continuous Delivery with CloudBees Jenkins Platform and AWS Lambda