Jenkins :- How to upload to Amazon S3 bucket using Jenkins

Pranesh Prashar
5 min readApr 7, 2022

Let’s try to upload a folder which contains some files or folders inside and try to upload it using jenkins to Amazon S3 bucket.

Step 1 :- Create a new bucket in Jenkins

Login to your account and go to S3 and create a new bucket there.

Give your bucket a name and region where files should be uploaded as S3 is global so it doesnot matter which region you choose. But make it public by unselecting the block all option in s3. If you select that then it will be private and cannot be accessed publicly.

After creating your bucket it will look like this :

Now our step 1 is complete with creating the s3 bucket. Now let’s move on to the other step .

Step 2 :- Install s3 plugins in jenkins :-

Go to your jenkins dashboard and click on manage jenkins.

Click on Manage plugins

After that click on available and in the search bar click on the s3 to search for the plugins and install it.

There are many s3 plugins but you have to download the one which allows you to push files to s3 , which is S3 publisher plugin which I have installed in jenkins.

Here step 2 is complete and now we will move on to the next step.

Step 3 :- Configuring s3 in jenkins :-

Now go to the configure system

In the configure you will find S3 option in the end.

Provide with the necessary details like below :-

Please provide a profile name, access key and secret access key for your AWS account. also, Create an IAM user with the relevant S3 Permissions.

If your credentials are right and if you click on test connections it will be prompted with check passed message.

Now here our step 3 is complete and we move on to next step.

Step 4 :- creating job in jenkins for s3 :-

Now we have configured jenkins for s3 so we need to create a job and tell that job what to do. so let’s create a job.

Go to that project and click on configure

after clicking on configure click on post-build actions

After that click on add build steps and there choose s3 copy artifects

In this you have to give your credentials and name of the files you have to upload.

While uploading the file make sure your file is in the workspace of jenkins which make things a lot easy.

If you don’t know the location of your workspace. you can check in by going to

Dashboard -> Configuration and there in the very firs line you will get the working directory for the jenkins.

Destination bucket means the bucket name you have created in the S3 amazon

Here you give the location of your choice and click on no upload on build failure

Click on save and go to job and click on build now.

You can check your output by going into the console output

I have run a script which does a small work but if you want to check whether it working or not just add any file in working directory of your job. you can do something like this. It will make an empty file in your job workspace and you can upload that in s3.

touch /var/lib/jenkins/workspace/<your job name>/abc.txt

After a success in console output you can check your file in amazon S3.

This is how my workspace looks like.

That’s all for uploading in S3.

--

--