是否可以通过这种方式集成AWS Codepipeline和Jenkins?

时间:2019-06-05 10:54:34

标签: amazon-web-services jenkins aws-codepipeline

我正在尝试为大量使用AWS堆栈的项目的CI设置管道。我们已经有Bitbucket和Jenkins服务器,因此理想情况下,我希望避免创建具有重复功能的基础架构组件。

我想要得到的是:Jenkins执行单元/集成测试,构建工件,然后触发Codepipeline,后者部署CF堆栈并执行端到端测试。我能够使用AWS steps plugin,S3和Codepipeline的组合创建原始管道。

Jenkinsfile:

#!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执行的结果。我希望看到詹金斯的一切。

我看到哪些选项?

  1. 忘记Codepipeline,仅使用来自AWS Steps插件的命令来部署测试堆栈并通过脚本执行端到端测试。

  2. 遵循AWS four-steps pipeline tutorial。如果我正确理解,则此解决方案将需要主动轮询SCM并将代码拉到AWS。

我想念什么吗?

1 个答案:

答案 0 :(得分:1)

现在,CodePipeline具有直接的Bitbucket云支持[1],还直接支持jenkins作为自定义阶段[2],您可以设置CodePipeline,它将使用bitbucket作为源阶段,并将jenkins动作作为阶段的一部分,以便我们可以仍然使用詹金斯进行所有测试,一旦詹金斯获得成功,我们就可以继续进行到CloudFormation的部署。

[1] https://aws.amazon.com/about-aws/whats-new/2019/12/aws-codepipeline-now-supports-atlassian-bitbucket-cloud/

[2] https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-four-stage-pipeline.html