Trigger Jenkins job when a S3 file is updated

Viewed 5533

I'm looking for a way to trigger my Jenkins job whenever a file is created or updated in S3. I can't seem to find anything by usual means of search. It is always upload artifacts to S3, but rarely download and even then I can't seem to find a way to trigger of the actual update process. The only way I currently can figure out how to do this at all, would be to sync the file periodically and compare the hash to previous versions, but that is a really terrible solution. The idea behind this would be to have an agency (which does not have access to our Jenkins) upload their build artifacts and to trigger a deployment from that.

3 Answers

To implement S3 Upload > Publish to SQS > Trigger Jenkins Build (assuming you have appropriate AWS Users, Roles and Policies attached):

Create an AWS SQS Queue

After creating an AWS SQS Queue, on AWS S3 bucket we need to configure:

  1. S3 Bucket "Events" section to register an "Object Create" event

  2. Provide the SQS Queue name. Detailed documentation.

On Jenkins, we need to:


  1. Install Plugin AWS SQS from the Jenkins Install Plugin Page

  2. Configure AWS SQS Plugin to point to SQS queue in Jenkins System Configuration

  3. Configure the Jenkins Job to "Trigger build when a message is published to an Amazon SQS queue"

  4. Note that Jenkins user MUST have Read access to SQS(all Read fucntions) in addition to S3 access.

Now whenever someone adds/updates anything on the bucket S3 sends an event notification the SQS which is then polled by the Jenkins AWS SQS plugin and the respective Job Build is triggered!

This article explains the process in detail AWS to Github to Jenkins. If you are just using S3 then you would skip the Github part.

Related