Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Jenkins job when a S3 file is updated

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.

like image 932
autarch princeps Avatar asked Aug 09 '17 08:08

autarch princeps


2 Answers

You can use a combination of SNS Notifications for new artifacts in the S3 bucket https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html and the Jenkins AWS SQS plugin to trigger a build (https://github.com/jenkinsci/aws-sqs-plugin)

A little bit of manual configuration is required in terms of the AWS SQS plugin, but it should work.

S3 Upload > SNS Notification > Publish to SQS > Trigger Jenkins Build

Ideally it would be straight to Jenkins like so: S3 Upload > SNS Notification > Publish to Jenkins HTTP Endpoint > Trigger Jenkins Build

Hope this helps

like image 134
Dhruv Parpia Avatar answered Sep 20 '22 15:09

Dhruv Parpia


We can write a icron job if linux or powershell script if windows, which queries a particular s3 bucket for the given string, if it finds then u can trigger the Jenkins job. For doing this, the Jenkins instance must be in the AWS itself if we are trying to add an IAM role, if not we need to add aws credentials.

like image 40
Litty Philip Avatar answered Sep 22 '22 15:09

Litty Philip