Gitlab +Jenkins +S3 部署静态页面

发布时间:2020-06-01 20:08:48 作者:wzlinux
来源:网络 阅读:571

一、Introduction

This article provides instructions to setup a basic deployment using Jenkins to Amazon S3 by pulling the source code from GitLab and pushing it to a S3 bucket. Deployment automation using Jenkins saves us from manually upload files to the S3 bucket using AWS online console. In addition to saving time, this method pushes the exact code that was committed in the latest Git push, therefore avoiding upload of wrong files. This is useful for static web site stored on S3 having a large number of files.

二、Pre-requisite

OS: Mac OS but the main ideas are OS agnostic.

It is assumed that you already have a static webpage on AWS S3. If not, you can check out instructions from AWS documentation: http://docs.aws.amazon.com/AmazonS3/latest/dev/HostingWebsiteOnS3Setup.html

You should also have your project added in GitLab. If not, you can have a look at their documentation: https://docs.gitlab.com/ee/gitlab-basics/create-project.html

Install Jenkins

Setup to pull project from GitLab

Establish SSH authentication between your local machine and GitLab.

Jenkins->Credentials->System->Global credentials (unrestricted) -> Add Credentials

Kind: SSH Username with private key.
Select Private Key and paste the private key.
Press OK

Gitlab +Jenkins +S3 部署静态页面

Manage Jenkins->Configure System
Add your Git username and email under Git plugin section

Gitlab +Jenkins +S3 部署静态页面

Jenkins->New Item

Enter any name for this Job
Select Freestyle Project
Press Ok

Gitlab +Jenkins +S3 部署静态页面

Fill in Git project URL and select credential to use (created in step 2) under Source Code Management tab.
Press Save.

Gitlab +Jenkins +S3 部署静态页面

Gitlab +Jenkins +S3 部署静态页面

If successful, you should see a blue or green ball. You can check the logs by clicking on the blue/green ball.

Gitlab +Jenkins +S3 部署静态页面

To check if the project is correctly pulled from git to Jenkins workspace, click on Workspace. You should see the same files that are in your Git repository.

Gitlab +Jenkins +S3 部署静态页面

Pushing project to Amazon S3

If you server is EC2, you can use IAM Role to attach to your EC2.

apt install awscli

https://docs.aws.amazon.com/zh_cn/cli/latest/userguide/cli-chap-install.html

Return to the job created in Jenkins and click configure
Go to the Build section
Enter:

aws s3 sync . s3://beauty.wzlinux.com/ --region eu-west-3 --delete --exclude ".git/*";

explanation: the first line tells Jenkins where to find s3cmd command by adding its location to PATH
the second line uses s3cmd to copy all (.) to a S3 bucket name optimus.com
--delete-removed will remove deleted files from S3
--exclude '.git/' excludes the git directory to sync to S3.
Click Save
Click Build Now

Gitlab +Jenkins +S3 部署静态页面

By checking the job’s log, you should see that Jenkins pulled the code from Git and pushed it to AWS S3.
That’s it! I hope this has helped you.

License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

欢迎大家扫码关注,获取更多信息

Gitlab +Jenkins +S3 部署静态页面

推荐阅读:
  1. Jenkins Gitlab持续集成打包平台搭建
  2. 如何使用python-Jenkins批量创建和修改jobs

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

jenkins j gitl

上一篇:Java 搞定 SQL 集合运算的最简方法

下一篇:curl 请求返回 301 Moved Permanent

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》