7

Do you know how to execute AWS CLI command inside a Jenkinsfile in order to build a pipeline? I didn't find any plugins

3 Answers 3

25

First you need install aws cli on your server and make sure the jenkins user has permissions to run it.

Or simply use the Amazon AMI when creating the EC2 instance, it comes with the aws cli.

Assign a role the instance with the appropriate policy. ( it is simpler that using user key in aws configure )

Within your pipeline steps use sh 'aws ...'

Sign up to request clarification or add additional context in comments.

1 Comment

any idea how we can run aws cli in jenkins if jenkins is running inside docker? I have posted my question here
1

First of all you need to install AWS CLI in Jenkins instance in order to perform calls to your environment.

To setup it you need to create a new user to Jenkins in AWS and configure properly the keys. Take a look here: http://docs.aws.amazon.com/systems-manager/latest/userguide/automation-jenkins.html

After that you can do calls inside your Jenkins jobs using 'Shell commands' to AWS CLI:

aws ec2 describe-security-groups

If you are using Ansible as your automation tool, take a look here: https://aws.amazon.com/blogs/apn/getting-started-with-ansible-and-dynamic-amazon-ec2-inventory-management/

Comments

0

I used ubuntu:latest as an agent and installed dependencies. Here is what fi worked for me:

   stage ('Install dependencies'){
        steps{
          script{    sh '''
                            apt-get update
                            apt-get install -y docker.io unzip curl
                            rm -rf awscliv2.zip aws/
                            curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
                            unzip -o awscliv2.zip
                            ./aws/install
                                
                            docker --version
                            aws --version
                        '''
                    
                }
       }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.