AWS CLI plugin

The AWS CLI plugin provisions the AWS CLI in your Jenkins 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.

Copyright © 2010-2020 CloudBees, Inc.Online version published by CloudBees, Inc. under the Creative Commons Attribution-ShareAlike 4.0 license.CloudBees and CloudBees DevOptics are registered trademarks and CloudBees Core, CloudBees Flow, CloudBees Flow Deploy, CloudBees Flow DevOps Insight, CloudBees Flow DevOps Foresight, CloudBees Flow Release, CloudBees Accelerator, CloudBees Accelerator ElectricInsight, CloudBees Accelerator Electric Make, CloudBees CodeShip, CloudBees Jenkins Enterprise, CloudBees Jenkins Platform, CloudBees Jenkins Operations Center, and DEV@cloud are trademarks of CloudBees, Inc. Most CloudBees products are commonly referred to by their short names — Accelerator, Automation Platform, Flow, Deploy, Foresight, Release, Insight, and eMake — throughout various types of CloudBees product-specific documentation. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Jenkins is a registered trademark of the non-profit Software in the Public Interest organization. Used with permission. See here for more info about the Jenkins project. The registered trademark Jenkins® is used pursuant to a sublicense from the Jenkins project and Software in the Public Interest, Inc. Read more at www.cloudbees.com/jenkins/about. Apache, Apache Ant, Apache Maven, Ant and Maven are trademarks of The Apache Software Foundation. Used with permission. No endorsement by The Apache Software Foundation is implied by the use of these marks.Other names may be trademarks of their respective owners. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this content, and CloudBees was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this content, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.