6

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

2 Answers 2

23

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 ...'

1
  • any idea how we can run aws cli in jenkins if jenkins is running inside docker? I have posted my question here
    – aquaman
    Nov 1, 2021 at 3:51
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/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.