-
Jenkins安装
具体请参考官网 https://jenkins.io
(1)yum install -y java-1.8.0-openjdk-devel
(2)yum update -y aws-cli #更新AWS CLI,如没有安装AWS CLI请事先安装。
(3)wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
(4)rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
(5)yum install jenkins -y -
git 安装
具体参考官网 http://git-scm.com
(1)yum install -y git -
配置AWS 认证
(1)配置Jenkins使用AWS IAM用户权限
cd ~jenkins
sudo -u jenkins aws configure #此处配置AKSK所对应的IAM用户权限只需附加AWS托管策略AWSCodeCommitPowerUser即可。 -
配置Git以使用IAM凭据和HTTP路径访问AWS CodeCommit托管的存储库
(1)
sudo -u jenkins git config --global credential.helper ‘!aws codecommit credential-helper $@’
sudo -u jenkins git config --global credential.useHttpPath true
sudo -u jenkins git config --global user.email “me@mycompany.com” #替换自己的email地址
sudo -u jenkins git config --global user.name “MyJenkinsServer” #替换自己的用户名 -
启动Jenkins
(1)
sudo service jenkins start
sudo chkconfig jenkins on -
配置Jenkins全局安全参数
(1)Open the Jenkins home page (http://:8080) in your browser.
(2)Select Manage Jenkins and Configure Global Security.
(3)Select the Enable Security check box.
(4)Under Security Realm, select the Jenkins’ own user database radio button.
(5)Clear the Allow users to sign up check box.
(6)Under Authorization, select the Logged-in users can do anything radio button. -
安装Git/AWS Codecommit插件
(1)Select Manage Jenkins and Manage Plugins.
(2)On the Available tab, use the Filter box to find Git/Codecommit Plugin.
(3)Select the Install check box next to Git Plugin.
(4)Choose Download now and install after restart. -
创建Jenkins Job
(1)From the Jenkins home page, select New Item.
(2)Select Build a free-style software project.
(3)For the project name, enter “Demo”.
(4)For Source Code Management, choose Git.
(5)For the repository URL, enter “https://git-codecommit.us-east-1.amazonaws.com/v1/repos/DemoRepo”.(Note the “Branches to build”.)
(6)For the Build Trigger, select Poll SCM with a schedule of H/05 * * * *. #对于轮询周期,请根据实际情况进行配置。详情点击Jenkins界面对应功能右侧的“?”进行查看。
exp:
TZ=CST #时区
H/05 * * * * #轮询周期(7)For the Build under Add Build Step select Execute Shell and in the Command text box, exp “cat /var/lib/jenkins/workspace/CodecommitTest/Code1.txt”.
(8)Click Save. -
测试结果
(1)git端编辑并上传新版代码(基于已配置git远程存储库及远程分支的情况)
echo “Build test for Jenkins job” >> Code1.txt
git add Code1.txt
git commit -m “the 1th job test”
git push origin BranchName
(2)等待轮询周期时间(比如设置的5分钟)登入Jenkins控制台,如果配置无误,你会看到一个新的build被触发。
AWS Codecommit + Jenkins实现CICD
于 2022-03-18 17:51:37 首次发布