aws codesuit 在codebuild和codepipeline中集成jenkins

news2024/10/5 22:39:11

codebuild集成jenkins

  • https://docs.aws.amazon.com/zh_cn/codebuild/latest/userguide/jenkins-plugin.html

  • Setting up a CI/CD pipeline by integrating Jenkins with AWS CodeBuild and AWS CodeDeploy

source选择本地的gitlab仓库,创建一个简单的springboot项目

在这里插入图片描述

在jenkins中下载安装codebuild和codepipeline插件

https://github.com/jenkinsci?q=aws-code&type=all&language=&sort=

在这里插入图片描述

源配置为本地的gitlab

在这里插入图片描述

在Build Steps中增加aws codebuild的步骤(需要配置aksk),注意由于创建codebuild项目的时候选择无source,所以需要欸之jenkins作为source。jenkins插件需要将gitlab仓库上传到s3中,然后交由codebuild构建。
在这里插入图片描述

直接构建,在构建中能看到具体的codebuild项目信息

在这里插入图片描述

在codebuild控制台查看构建,提交者是jenkins插件, 并且虽然项目为nosource,但是实际上sourceversion仍旧能指向s3桶

在这里插入图片描述

相关错误

codebuild插件会实时将codebuild项目的构建日志回传到jenkins的控制台输出中

(1)没有凭证

需要为jenkins插件配置aksk凭证

[AWS CodeBuild Plugin] Authorization error
	> Invalid credentials ID. Verify that the credentials are of type CodeBuildCredentials and are accessible in this project. (Service: null; Status Code: 0; Error Code: null; Request ID: null; Proxy: null)
Build step 'AWS CodeBuild' changed build result to FAILURE

(2)没有项目

如果没有codebuild项目直接构建,jenkins找不到codebuild项目则报错

[AWS CodeBuild Plugin] Starting build with 
	> project name: helloBoot
	> Download build artifacts: false
[AWS CodeBuild Plugin] Error when calling CodeBuild StartBuild: 
	> Project cannot be found: arn:aws-cn:codebuild:cn-north-1:xxxxxxxxx:project/helloBoot (Service: AWSCodeBuild; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: a5627552-9ab3-48ff-8431-a9a3f8ce1b19; Proxy: )
Build step 'AWS CodeBuild' changed build result to FAILURE

(3)没有pom文件

配置了projectsource默认使用codebuild的source,但是codebuild项目创建时配置了nosource,因此没有任何代码,因此也找不到pom文件。需要在构建项目中配置为jenkins源

[AWS CodeBuild Plugin] 2023/01/19 10:59:44 Running command mvn test && mvn package
[AWS CodeBuild Plugin] [INFO] Scanning for projects...
[AWS CodeBuild Plugin] [INFO] ------------------------------------------------------------------------
[AWS CodeBuild Plugin] [INFO] BUILD FAILURE
[AWS CodeBuild Plugin] [INFO] ------------------------------------------------------------------------
[AWS CodeBuild Plugin] [INFO] Total time:  0.086 s
[AWS CodeBuild Plugin] [INFO] Finished at: 2023-01-19T10:59:51Z
[AWS CodeBuild Plugin] [INFO] ------------------------------------------------------------------------
[AWS CodeBuild Plugin] [ERROR] The goal you specified requires a project to execute but there is no POM in this directory 

(4)项目状态有误

选择jenkins项目后必须将source配置为s3,且指定s3桶名和路径

[AWS CodeBuild Plugin] CodeBuild configured improperly in project settings
	> When using Jenkins source, sourceTypeOverride must be S3 and you must specify both sourceTypeOverride and sourceLocationOverride
Build step 'AWS CodeBuild' changed build result to FAILURE

(5)没有权限

由于jenkins插件需要将源码上传到s3中,codebuild才能从s3获取到,如果codebuild角色无法访问s3,则会出先access denied的错误

[AWS CodeBuild Plugin] AccessDenied: Access Denied
[AWS CodeBuild Plugin] 	status code: 403, request id: 2960Q91F2RMZKG0W, host id: QBumXMzSyqV75541Ad0kqbBRga9Tzl7Ge5K/DsJ2OoFiOi9DDFExdIByxpRdZU+ZBk2knMNQQcM= for primary source and source version 19pEIsR9kR7fDGMSvYKv6LDauF8Rndsx
[AWS CodeBuild Plugin] Build helloBoot:56dfba8f-d367-450d-95a9-c9b24e5a6816 failed
	> AccessDenied: Access Denied	status code: 403, request id: 2960Q91F2RMZKG0W, host id: QBumXMzSyqV75541Ad0kqbBRga9Tzl7Ge5K/DsJ2OoFiOi9DDFExdIByxpRdZU+ZBk2knMNQQcM= for primary source and source version 19pEIsR9kR7fDGMSvYKv6LDauF8Rndsx (status code: CLIENT_ERROR)
Build step 'AWS CodeBuild' changed build result to FAILURE

如果使用流水线脚本,可使用片段生成器生成如下配置

awsCodeBuild artifactEncryptionDisabledOverride: '', artifactLocationOverride: '', artifactNameOverride: '', artifactNamespaceOverride: '', artifactPackagingOverride: '', artifactPathOverride: '', artifactTypeOverride: '', awsAccessKey: 'xxxxxxxx', awsSecretKey: 'yo7Lxxxxxxxxxxxxxxa7JU', buildSpecFile: '', buildTimeoutOverride: '', cacheLocationOverride: '', cacheModesOverride: '', cacheTypeOverride: '', certificateOverride: '', cloudWatchLogsGroupNameOverride: '', cloudWatchLogsStatusOverride: '', cloudWatchLogsStreamNameOverride: '', computeTypeOverride: '', credentialsId: '', credentialsType: 'keys', cwlStreamingDisabled: '', downloadArtifacts: 'false', downloadArtifactsRelativePath: '', envParameters: '', envVariables: '', environmentTypeOverride: '', exceptionFailureMode: '', gitCloneDepthOverride: '', imageOverride: '', insecureSslOverride: '', localSourcePath: '', overrideArtifactName: '', privilegedModeOverride: '', projectName: 'helloBoot', proxyHost: '', proxyPort: '', region: 'cn-north-1', reportBuildStatusOverride: '', s3LogsEncryptionDisabledOverride: '', s3LogsLocationOverride: '', s3LogsStatusOverride: '', secondaryArtifactsOverride: '', secondarySourcesOverride: '', secondarySourcesVersionOverride: '', serviceRoleOverride: '', sourceControlType: 'jenkins', sourceLocationOverride: 'codebuild-bjs-input-bucket/helloBooot.zip', sourceTypeOverride: 'S3', sourceVersion: '', sseAlgorithm: 'AES256', workspaceExcludes: '', workspaceIncludes: '', workspaceSubdir: ''

codepipeline集成jenkins

codepipeline创建一个四阶段管道

项目结构如下图所示

在这里插入图片描述

以上架构中,由于中国区不支持在pipeline中配置github作为source,所以将codecommit作为source阶段,支持jenkins的只有build和test阶段

在这里插入图片描述

在jenkins安装codepipeline插件

在这里插入图片描述

codepipeline侧配置

按照官方示例创建一个三阶段pipeline(简单起见,跳过测试阶段)

配置build阶段为jenkins,填写参数如下

provider需要和jenkins插件配置一致,url可以填写ec2的ip:port

在这里插入图片描述

jenkins侧配置

主要是安装codepipeline插件,关键配置如下

aksk是为jenkins插件授权查询codepipeline任务状态的,provider需要和codepipeline中配置一致

在这里插入图片描述

配置触发器为每分钟轮询,这样jenkins插件会每分钟轮询codepipeline状态,检测构建任务的触发

在这里插入图片描述

轮询日志如下,如果没有权限会报错

正常结果

Started on Jan 19, 2023, 2:07:00 PM
[AWS CodePipeline Plugin] Polling for jobs for action type id: [Owner: Custom, Category: Build, Provider: testJenkins, Version: 1, ProjectName: mypipeline]
[AWS CodePipeline Plugin] No jobs found.
Done. Took 48 sec
No changes

插件没有凭证的结果

Started on Jan 19, 2023, 2:08:00 PM
[AWS CodePipeline Plugin] Polling for jobs for action type id: [Owner: Custom, Category: Build, Provider: testJenkins, Version: 1, ProjectName: mypipeline]
ERROR: Failed to record SCM polling for hudson.model.FreeStyleProject@341d4f5c[mypipeline]
hudson.model.Failure: 
AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified.
The AWS credentials provided are not valid.

插件配置错误区域的报错

Started on Jan 19, 2023, 2:16:00 PM
[AWS CodePipeline Plugin] Polling for jobs for action type id: [Owner: Custom, Category: Build, Provider: testJenkins, Version: 1, ProjectName: mypipeline]
ERROR: Failed to record SCM polling for hudson.model.FreeStyleProject@341d4f5c[mypipeline]
com.amazonaws.services.codepipeline.model.ActionTypeNotFoundException: ActionType (Category: 'Build', Owner: 'Custom', Provider: 'testJenkins', Version: '1') is not available (Service: AWSCodePipeline; Status Code: 400; Error Code: ActionTypeNotFoundException; Request ID: e4a70f8a-e125-43d0-9467-e6c4b5292840; Proxy: null)

codepipeline的build阶段等待10分钟超时,应该是插件没有识别到pipeline任务

Failed to upload output artifact(s): The number of output artifacts in the Jenkins project and in the pipeline action do not match. Configure the output locations of your Jenkins project to match the pipeline action's output artifacts. Number of output locations in Jenkins project: 0, number of output artifacts in the pipeline action: 1 [Pipeline: test-jenkins, stage: Build, action: Build].

检查配置后重新触发,可见jenkins插件识别到任务,并将s3的输出内容下载到本地的/home/ec2-user/.jenkins/workspace/mypipeline目录,但是仍旧有错误

[AWS CodePipeline Plugin] Job 'c257736e-6cb2-4d00-ba38-fad6b44aba49' received
[AWS CodePipeline Plugin] Acknowledged job with ID: c257736e-6cb2-4d00-ba38-fad6b44aba49
[AWS CodePipeline Plugin] Clearing workspace '/home/ec2-user/.jenkins/workspace/mypipeline' before download
[AWS CodePipeline Plugin] Detected compression type: Zip
[AWS CodePipeline Plugin] Successfully downloaded artifact from AWS CodePipeline
[AWS CodePipeline Plugin] Extracting '/home/ec2-user/.jenkins/workspace/mypipeline/RtMO8D2' to '/home/ec2-user/.jenkins/workspace/mypipeline'
[AWS CodePipeline Plugin] Artifact uncompressed successfully
...

构建完成的日志如下,但是artifact出现错误

[INFO] Building war: /home/ec2-user/.jenkins/workspace/mypipeline/target/unicorn-web-project.war
[INFO] WEB-INF/web.xml already added, skipping
...
[AWS CodePipeline Plugin] Publishing artifacts
[AWS CodePipeline Plugin] The number of output artifacts in the Jenkins project and in the pipeline action do not match. Configure the output locations of your Jenkins project to match the pipeline action's output artifacts. Number of output locations in Jenkins project: 0, number of output artifacts in the pipeline action: 1 [Pipeline: test-jenkins, stage: Build, action: Build].

jenkins插件的逻辑和codepipeline一致,最终会将构建结果回传到s3桶

在这里插入图片描述

测试阶段仍旧报错,需要配置codepipeline的输入为buildartifact,否则该阶段获取的是源码包

[AWS CodePipeline Plugin] The number of output artifacts in the Jenkins project and in the pipeline action do not match. Configure the output locations of your Jenkins project to match the pipeline action's output artifacts. Number of output locations in Jenkins project: 1, number of output artifacts in the pipeline action: 0 [Pipeline: test-jenkins, stage: Test, action: test].
[AWS CodePipeline Plugin] Stacktrace:

在这里插入图片描述

由于jenkins不需要预置环境,并且是测试demo,pipeline的执行速度非常快

经过十几次的尝试,最终完成一个四阶段code pipeline和jenkins的集成

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/173229.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Cert Manager 申请 SSL 证书流程及相关概念 - 一

2022.3.9 用 cert-manager 申请成功通配符证书 (*.ewhisper.cn), 2022.4.30 该证书距离过期还有 30 天,cert-manager 进行自动续期,但是却失败了。😱😱😱 然后过了几天,在 2022.5.8, 最终成功了。如下图&a…

Vue3 项目实战 —— 后台管理系统( pc端 ) —— 动态多级导航菜单顶部侧边联动

前期回顾 0.活在风浪里的博客_CSDN博客-vue2,开源项目,Js领域博主0.活在风浪里擅长vue2,开源项目,Js,等方面的知识,0.活在风浪里关注css,safari,html5,scss,elementui,前端,es6,正则表达式,vue.js,express,ajax,webpack,echarts,json,html,typescript,sass,https,面试,ch…

离散数学-图论-图的矩阵表示(12.1)

图的矩阵表示 1 关联矩阵 定义&#xff1a;设无向图G<V,E>,V{v1,v2,⋅⋅⋅,vnv_1,v_2,,v_nv1​,v2​,⋅⋅⋅,vn​},E{e1,e2,⋅⋅⋅,eme_1,e_2,,e_me1​,e2​,⋅⋅⋅,em​},令mijm_{ij}mij​为顶点viv_ivi​与边eje_jej​的关联次数&#xff0c;则称(mij)nm(m_{ij})_{nm}…

九龙证券|景气度复苏与库存拐点双击,这个行业获主力看好!

今天计算机职业、电子、非银金融职业净流入规划居前&#xff0c;9股主力资金净流入超2亿元。 证券时报数据宝统计&#xff0c;今天沪深两市主力资金净流出46.1亿元&#xff0c;其间创业板净流出3.57亿元&#xff0c;沪深300成份股净流入28.21亿元。 申万一级职业中&#xff0c…

SpringAMQP - Work Queue 工作消息队列

目录 介绍 案例 测试 改进&#xff1a; 介绍 Work queues也被称为&#xff08;Task queues&#xff09;&#xff0c;任务模型简单来说就是让多个消费者绑定到一个队列&#xff0c;共同消费队列中的消息当消息处理比较耗时的时候&#xff0c;可能生产消息的速度会远远大于消…

机器人与未来

我们生活在“普适机器人”时代&#xff0c;机器人将像今天的智能手机一样融入日常生活&#xff0c;完成许多专门任务&#xff0c;并经常与人类并肩工作。 机器人革命将创造一个比现在更加生动和充满活力的未来。 到 2022 年&#xff0c;机器人将获得如此大的吸引力&#xff0…

全国地名点地统计模式分析

前言用不同的空间点模式分析方法&#xff0c;综合得出全国地名数据点的空间分布模式属于随机分布、均匀分布、聚集分布中的哪一种。一、点模式分析空间点模式分析是一种根据地理实体或事件的空间位置研究其分布模式的空间分析方法 。 空间点分布模式通常分为三种&#xff1a;随…

从汇编的角度去审视函数的调用【函数栈帧】

文章目录函数栈帧栈寄存器相关汇编指令函数栈帧的创建函数栈帧的销毁函数栈帧 我们在写C语言代码的时候&#xff0c;经常会把一个独立的功能抽象为函数&#xff0c;所以C程序是以函数为基本单位的。 那函数是如何调用的&#xff1f;函数的返回值又是如何待会的&#xff1f;函数…

17种编程语言实现排序算法-冒泡排序

开源地址 https://gitee.com/lblbc/simple-works/tree/master/sort 覆盖语言&#xff1a;C、C、C#、Java、Kotlin、Dart、Go、JavaScript(JS)、TypeScript(TS)、ArkTS、swift、PHP。 覆盖平台&#xff1a;安卓(Java、Kotlin)、iOS(SwiftUI)、Flutter(Dart)、Window桌面(C#)、前…

离散数学-集合论-函数(10)

函数 1 函数的概念 1.1 函数的定义 设&#x1d453;是非空集A到B的关系, 如果对每个&#x1d465;∈A, 都存在唯一的&#x1d466;∈B, 使得<&#x1d465;, &#x1d466;>∈&#x1d453;, 则称关系&#x1d453;为A到B的函数(Function), 也可称为映射(Mapping)或变…

PID优化系列之给定值斜坡函数(PLC代码+Simulink仿真测试)

很多变频器里的工艺PID,都有"PID给定值变化时间"这个参数,这里的给定值变化时间我们可以利用斜坡函数实现,当然也可以利用PT1 低通滤波器对给定值进行平滑。给定值缓慢变化在很多闭环控制系统里很重要,比如收放卷在初始建张阶段目标值不建议突变容易将卷材拉断(…

聊聊外包团队的高效管理机制

这是鼎叔的第四十七篇原创文章。行业大牛和刚毕业的小白&#xff0c;都可以进来聊聊。欢迎关注本人专栏和微信公众号《敏捷测试转型》&#xff0c;大量原创思考文章陆续推出。对于大规模的外包团队&#xff0c;需要一个易用的外包管理OA系统&#xff0c;才能提高日常交付效率。…

LINUX学习之时间日期类命令(五)

date命令 命令描述 date命令用于在Linux系统中显示或设置当前系统时间。它可以显示当前日期和时间&#xff0c;并允许用户格式化输出。它还可以用于将系统时间设置为指定的日期和时间。使用格式化字符串&#xff0c;可以自定义输出格式 以下是data命令的常用参数&#xff1a…

【Simulink】使用Model Explorer设置模块变量初值

问题背景 最近在学习滑模控制&#xff0c;看到b站上的视频和文章&#xff0c;打算自己照着做一遍&#xff1a; 1、滑模控制的基本原理实际仿真中却遇到了一个小问题&#xff0c;不知道怎么设置变量x1的初值&#xff08;不能用pulse generator给初始脉冲&#xff09; 这里的x1是…

【JavaEE】单例模式(饿汉懒汉)

目录 前言&#xff1a; 单线程下的单例模式 饿汉模式 懒汉模式 多线程下的单例模式 懒汉模式的修改 1.加锁 2.有条件的加锁 3.解决内存可见性和指令重排序 前言&#xff1a; 本片文章介绍设计模式中的一个模式——单例模式。 单例模式就是只允许创建出一个实例的类。…

离散数学-图论-树(13)

树 1 无向树及其性质 定义1&#xff1a;连通无回路的无向图称为无向树,简称树.每个连通分支都是树的无向图称为森林.平凡图称为平凡树.在无向树中,悬挂顶点称为树叶,度数大于或等于2的顶点称为分支点. 定义2 设G<V,E>是n阶m条边的无向图&#xff0c;则下面各命题是等价…

c语言attribute关键字参数(详细)总结附示例快速掌握

目录一、简介二、参数详解2.1 section&#xff1a;自定义段2.2 aligned&#xff1a;对齐2.3 packed&#xff1a;对齐2.4 format&#xff1a;检查函数变参格式2.5 used2.6 unused2.7 at 绝对定位2.8 constructor2.9 destructor2.10 weak&#xff1a;弱声明2.11 alias&#xff1a…

macOS spotlight 聚焦 搜索范围自定义

文章目录Intro禁用不需要的查找范围&#xff0c;减少 spotlight 工作量/资源损耗搜索结果中的每个分类各自代表什么&#xff1f;Intro MBA升级系统之后&#xff0c;第一次充满电用了12h&#xff0c;之后的使用过程中掉电也很快。 新版本信息&#xff1a;macOS Ventura 13.1 (2…

I.MX6ULL裸机开发笔记1:启动方式

目录 启动模式设置步骤 1、三大模式 2.选择内部介质 3.选择接口编号 4.介质属性 原理图 芯片手册截图 开机相关全部引脚 启动设置表 启动模式设置步骤 1、三大模式 熔丝模式&#xff1a;烧录一次&#xff0c;发布产品外部模式&#xff1a;USB、串口等内部&#xff1a…

Windows系统下利用Anaconda搭建MXNet框架

1、mxnet MXNet 是一个深度学习库&#xff0c;类似于Theano 和 TensorFlow。最近想搞下深度学习&#xff0c;于是便安装mxnet。之前安装过TensorFlow&#xff0c;也踩了很多坑&#xff0c;可谓是历经波折。有的时候&#xff0c;配置环境真的是一门玄学。 2、关于网上的一些教…