Host a static website on s3 using webhook jenkins
Hint: Read about webhook in jenkins
Note: this is a pipeline approach
ANS:
Step-1: Setup simple S3 Bucket
Step-2: here we are using Automated Pipeline Approaches
https://github.com/kushagra67414/jenkins-static-s3-deploy
It consists of Jenkins pipeline and policy required for s3 bucket to allow public access & index.html and error.html files
Step-3: Pipeline Setup
Create a new Pipeline project in Jenkins.
Pipeline =>
Add a webhook in the git repository.
webhook configuration is required if push commits in this repo jenkins will create a build.
Step-4: Run the pipeline to test that it works. It should upload the files to the S3 bucket.
First, configure the job.
Step-5: After configuring the job , build the project it must store the data in your s3 bucket but it might show an error because we have not configured the aws cli in jenkins users.
we are configuring aws cli because pipeline consist an aws cli commands and when pipeline executes it checks for the awi cli environmemt
Go to the jenkins user and configure aws cli to execute the command present in a pipeline.
First go to user:
> su — jenkins
> aws configure add secret key and access key of the root user or create an iam user with the policy of s3 bucket to access it and give credentials of iam user.
best practice is to create an iam user.
Step-6: Restart the jenkins and build the project
Command : systemctl restart jenkins
Console output: