AWS Codepipeline 和 Jenkins 可以这样集成吗?
Is it possible to integrate AWS Codepipeline and Jenkins in such a way?
我正在尝试为 CI 的项目设置管道,该项目大量使用 AWS 堆栈。我们已经有了 Bitbucket 和 Jenkins 服务器,所以理想情况下我想避免创建具有重复功能的基础设施组件。
我想要得到的:Jenkins 执行 unit/integration 测试,构建工件,然后触发 Codepipeline,它部署 CF 堆栈并执行端到端测试。我能够使用 AWS steps plugin、S3 和 Codepipeline 的组合创建原始管道。
詹金斯文件:
#!groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
sh "mvn clean package"
}
}
stage('S3upload') {
steps {
withAWS(region:'us-east-1',credentials:'JENKINS') {
s3Upload(bucket: 'somebucket', workingDir:'target', includePathPattern:'some.jar');
}
}
}
}
}
代码管道:
{
"pipeline": {
"name": "SomePipeline",
<...>
,
"stages": [
{
"name": "Source",
"actions": [
{
"name": "Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "S3",
"version": "1"
},
"runOrder": 1,
"configuration": {
"PollForSourceChanges": "false",
"S3Bucket": "somebucket",
"S3ObjectKey": "some.jar"
},
"outputArtifacts": [
{
"name": "SourceArtifact"
}
],
"inputArtifacts": [],
"region": "us-east-1"
}
]
},
{
"name": "DeployCognitoStack",
"actions": [
{
"name": "DeployCognitoStack",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CloudFormation",
"version": "1"
},
"runOrder": 1,
"configuration": {
"ActionMode": "CREATE_UPDATE",
"Capabilities": "CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND",
"RoleArn": "arn:aws:iam::*:role/CloudFormationRole",
"StackName": "cognitostacktest",
"TemplatePath": "SourceArtifact::cognito-stack.yaml"
},
"outputArtifacts": [],
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"region": "us-east-1"
}
]
},
{
"name": "DeployLambdaStack",
"actions": [
{
"name": "DeployLambdaStack",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CloudFormation",
"version": "1"
},
"runOrder": 1,
"configuration": {
"ActionMode": "CREATE_UPDATE",
"Capabilities": "CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND",
"RoleArn": "arn:aws:iam::*:role/CloudFormationRole",
"StackName": "lambdatest",
"TemplatePath": "SourceArtifact::lambda-stack.yaml"
},
"outputArtifacts": [],
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"region": "us-east-1"
}
]
},
<here should be test stage>
],
"version": 5
}
}
我不喜欢的是我需要分别查看 Jenkins 作业执行的结果和 Codepipeline 执行的结果。我更愿意在 Jenkins 中看到所有内容。
我看到了哪些选项:
忘记 Codepipeline,仅使用来自 AWS Steps 插件的命令来部署测试堆栈并通过脚本执行端到端测试。
关注AWS four-steps pipeline tutorial。如果我理解正确的话,这个解决方案将需要主动轮询 SCM 并将代码拉到 AWS。
我是不是漏掉了什么?
因为现在 CodePipeline 具有直接的 Bitbucket 云支持 [1] 并且还支持直接将 jenkins 作为自定义阶段 [2] 您可以设置 CodePipeline,它将使用 bitbucket 作为源阶段并将 jenkins 操作作为阶段的一部分,以便我们仍然可以使用 jenkins 进行所有测试,一旦 jenkis 成功,我们就可以继续部署到 CloudFormation。
[2]https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-four-stage-pipeline.html
我正在尝试为 CI 的项目设置管道,该项目大量使用 AWS 堆栈。我们已经有了 Bitbucket 和 Jenkins 服务器,所以理想情况下我想避免创建具有重复功能的基础设施组件。
我想要得到的:Jenkins 执行 unit/integration 测试,构建工件,然后触发 Codepipeline,它部署 CF 堆栈并执行端到端测试。我能够使用 AWS steps plugin、S3 和 Codepipeline 的组合创建原始管道。
詹金斯文件:
#!groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
sh "mvn clean package"
}
}
stage('S3upload') {
steps {
withAWS(region:'us-east-1',credentials:'JENKINS') {
s3Upload(bucket: 'somebucket', workingDir:'target', includePathPattern:'some.jar');
}
}
}
}
}
代码管道:
{
"pipeline": {
"name": "SomePipeline",
<...>
,
"stages": [
{
"name": "Source",
"actions": [
{
"name": "Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "S3",
"version": "1"
},
"runOrder": 1,
"configuration": {
"PollForSourceChanges": "false",
"S3Bucket": "somebucket",
"S3ObjectKey": "some.jar"
},
"outputArtifacts": [
{
"name": "SourceArtifact"
}
],
"inputArtifacts": [],
"region": "us-east-1"
}
]
},
{
"name": "DeployCognitoStack",
"actions": [
{
"name": "DeployCognitoStack",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CloudFormation",
"version": "1"
},
"runOrder": 1,
"configuration": {
"ActionMode": "CREATE_UPDATE",
"Capabilities": "CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND",
"RoleArn": "arn:aws:iam::*:role/CloudFormationRole",
"StackName": "cognitostacktest",
"TemplatePath": "SourceArtifact::cognito-stack.yaml"
},
"outputArtifacts": [],
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"region": "us-east-1"
}
]
},
{
"name": "DeployLambdaStack",
"actions": [
{
"name": "DeployLambdaStack",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CloudFormation",
"version": "1"
},
"runOrder": 1,
"configuration": {
"ActionMode": "CREATE_UPDATE",
"Capabilities": "CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND",
"RoleArn": "arn:aws:iam::*:role/CloudFormationRole",
"StackName": "lambdatest",
"TemplatePath": "SourceArtifact::lambda-stack.yaml"
},
"outputArtifacts": [],
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"region": "us-east-1"
}
]
},
<here should be test stage>
],
"version": 5
}
}
我不喜欢的是我需要分别查看 Jenkins 作业执行的结果和 Codepipeline 执行的结果。我更愿意在 Jenkins 中看到所有内容。
我看到了哪些选项:
忘记 Codepipeline,仅使用来自 AWS Steps 插件的命令来部署测试堆栈并通过脚本执行端到端测试。
关注AWS four-steps pipeline tutorial。如果我理解正确的话,这个解决方案将需要主动轮询 SCM 并将代码拉到 AWS。
我是不是漏掉了什么?
因为现在 CodePipeline 具有直接的 Bitbucket 云支持 [1] 并且还支持直接将 jenkins 作为自定义阶段 [2] 您可以设置 CodePipeline,它将使用 bitbucket 作为源阶段并将 jenkins 操作作为阶段的一部分,以便我们仍然可以使用 jenkins 进行所有测试,一旦 jenkis 成功,我们就可以继续部署到 CloudFormation。
[2]https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-four-stage-pipeline.html