AWS Codecommit + Jenkins实现CICD

  1. 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

  2. git 安装
    具体参考官网 http://git-scm.com
    (1)yum install -y git

  3. 配置AWS 认证
    (1)配置Jenkins使用AWS IAM用户权限
    cd ~jenkins
    sudo -u jenkins aws configure #此处配置AKSK所对应的IAM用户权限只需附加AWS托管策略AWSCodeCommitPowerUser即可。

  4. 配置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” #替换自己的用户名

  5. 启动Jenkins
    (1)
    sudo service jenkins start
    sudo chkconfig jenkins on

  6. 配置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.

  7. 安装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.

  8. 创建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.

  9. 测试结果
    (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被触发。

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值